Class: OData::AbstractQuery::Options::TopOption

Inherits:
OData::AbstractQuery::Option show all
Defined in:
lib/o_data/abstract_query/options/top_option.rb

Instance Attribute Summary

Attributes inherited from BasicOption

#key, #query, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OData::AbstractQuery::Option

#applies_to?, #option_name

Methods inherited from BasicOption

#inspect, #option_name

Constructor Details

#initialize(query, key, value = nil) ⇒ TopOption

Returns a new instance of TopOption.



9
10
11
# File 'lib/o_data/abstract_query/options/top_option.rb', line 9

def initialize(query, key, value = nil)
  super(query, key, value)
end

Class Method Details

.applies_to?(query) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/o_data/abstract_query/options/top_option.rb', line 13

def self.applies_to?(query)
  return false if query.segments.empty?
  return false unless query.segments.last.respond_to?(:countable?)
  query.segments.last.countable?
end

.option_nameObject



5
6
7
# File 'lib/o_data/abstract_query/options/top_option.rb', line 5

def self.option_name
  '$top'
end

.parse!(query, key, value = nil) ⇒ Object



19
20
21
22
23
# File 'lib/o_data/abstract_query/options/top_option.rb', line 19

def self.parse!(query, key, value = nil)
  return nil unless key == self.option_name
  
  query.Option(self, key, value.to_i)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/o_data/abstract_query/options/top_option.rb', line 25

def valid?
  return false if self.value.blank?
  self.value.to_i >= 1
end