Class: Ondotori::WebAPI::Api::DataRange
- Inherits:
-
Object
- Object
- Ondotori::WebAPI::Api::DataRange
- Defined in:
- lib/ondotori/webapi/api/data_range.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #add_data_range(params) ⇒ Object
-
#initialize(from: nil, to: nil, limit: nil) ⇒ DataRange
constructor
A new instance of DataRange.
- #validate(from, to, _limit) ⇒ Object
Constructor Details
#initialize(from: nil, to: nil, limit: nil) ⇒ DataRange
Returns a new instance of DataRange.
9 10 11 12 13 14 15 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 9 def initialize(from: nil, to: nil, limit: nil) validate(from, to, limit) @from = from @to = to @limit = limit.nil? ? 0 : [0, limit].max end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
7 8 9 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 7 def from @from end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 7 def limit @limit end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
7 8 9 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 7 def to @to end |
Instance Method Details
#add_data_range(params) ⇒ Object
27 28 29 30 31 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 27 def add_data_range(params) params["unixtime-from"] = @from.to_i unless @from.nil? params["unixtime-to"] = @to.to_i unless @to.nil? params["number"] = @limit if @limit != 0 end |
#validate(from, to, _limit) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ondotori/webapi/api/data_range.rb', line 17 def validate(from, to, _limit) [from, to].each do |param| next if param.nil? || param.instance_of?(Time) raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new( "from and to parameter must be nil or Time.", 9992 ) end end |