Project

year_array

0.0
No release in over 3 years
Low commit activity in last 3 years
Just an array wrapper to manage 8760 (or 8784) hourly values related to a year
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.8
~> 10.0
~> 3.0

Runtime

 Project Readme

YearArray

Build Status Coverage Status

It's basically an array wrapper used to play (do some check and calculation) with 8760 (or 8784) hourly values related to a year.

Installation

Add this line to your application's Gemfile:

gem 'year_array'

And then execute:

$ bundle

Or install it yourself as:

$ gem install year_array

Usage

Initialize

arr = Yarray.new(2018)
arr.to_s   => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ..., 0.0]"

will initialize the array to zero.

Otherwise pass the init value:

arr = Yarray.new(2018, value: 1.0)
arr.to_s   => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ..., 0.0]"

You can also pass an init array:

arr = Yarray.new(2018, arr: [0.0, 1.0, 2, 3])
arr.to_s   => "start_time: 2018-01-01 00:00:00 +0100, arr: [0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, ..., 0.0]"

The array will be truncated or filled with zero values in order to reach the correct number of hours in year.

Functions

ya1 = Yarray.new(2018, value: 1.0)
ya2 = Yarray.new(2018, value: 2.0)

ya1.size   # => 8760
ya1.year   # => 2018

# Operations on each element of array

# The result will be stored in a new yarray object (more memory expensive):
ya1 + ya2
ya1 - ya2
ya1 * ya2
ya1 / ya2

# The operation will be computed in the caller ya1:
ya1.add(ya2)
ya1.subtract(ya2)
ya1.multiply(ya2)
ya1.divide(ya2)


Yarray.min(ya1, ya2)   # return a Yarray object where each value is the minimum between value of ya1 and ya2
Yarray.max(ya1, ya2)   # return a Yarray object where each value is the maximum between value of ya1 and ya2

ya1.any_positive?
ya1.any_negative?

ya1.any do |v|
  v > 100
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/year_array. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the YearArray project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.