Class: Opencellid::Cell
- Inherits:
-
Object
- Object
- Opencellid::Cell
- Defined in:
- lib/opencellid/cell.rb
Overview
Models a Cell object, both as an output from the server and as an input to queries. When using an object of this type to specify query parameters, the class attributes that should be used as filters should be set to the desired values, while the other attributes should be set to nil
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#lac ⇒ Object
Returns the value of attribute lac.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#mcc ⇒ Object
Returns the value of attribute mcc.
-
#measures ⇒ Object
Returns the value of attribute measures.
-
#mnc ⇒ Object
Returns the value of attribute mnc.
-
#no_of_samples ⇒ Object
Returns the value of attribute no_of_samples.
-
#range ⇒ Object
Returns the value of attribute range.
Class Method Summary collapse
-
.from_element(element) ⇒ Cell
Parses the given element setting the information into a Cell object.
Instance Method Summary collapse
-
#add_measure(measure) ⇒ Object
Adds a new measure to this cell does NOT result in an add_measure call being invoked on the Opencellid object.
-
#has_measures? ⇒ bool
Indicates whether this cell contains measure objects.
-
#initialize(id, mnc, mcc, lac) ⇒ Cell
constructor
A new instance of Cell.
-
#to_lng_lat ⇒ Array
Returns an array containing the longitude and latitude of the cell, this method makes the Cell object to be compatible with mongoid_spacial gem.
-
#to_query_hash ⇒ Hash
Helper function that transforms the parameters of this cell in a hash of query parameters to be used with the library cell querying functions.
Constructor Details
#initialize(id, mnc, mcc, lac) ⇒ Cell
Returns a new instance of Cell.
17 18 19 20 21 22 23 |
# File 'lib/opencellid/cell.rb', line 17 def initialize(id, mnc, mcc, lac) @id = id @mnc = mnc @mcc = mcc @lac = lac @measures = [] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def id @id end |
#lac ⇒ Object
Returns the value of attribute lac.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def lac @lac end |
#lat ⇒ Object
Returns the value of attribute lat.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def lon @lon end |
#mcc ⇒ Object
Returns the value of attribute mcc.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def mcc @mcc end |
#measures ⇒ Object
Returns the value of attribute measures.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def measures @measures end |
#mnc ⇒ Object
Returns the value of attribute mnc.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def mnc @mnc end |
#no_of_samples ⇒ Object
Returns the value of attribute no_of_samples.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def no_of_samples @no_of_samples end |
#range ⇒ Object
Returns the value of attribute range.
11 12 13 |
# File 'lib/opencellid/cell.rb', line 11 def range @range end |
Class Method Details
.from_element(element) ⇒ Cell
Parses the given element setting the information into a Cell object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/opencellid/cell.rb', line 28 def self.from_element(element) return nil unless element raise ArgumentError, 'element must be of type XEXML::Element' unless element.is_a? REXML::Element raise ArgumentError, 'element must be a <cell>' unless element.name == 'cell' attrs = element.attributes result = Cell.new(::Opencellid.to_i_or_nil(attrs['cellId']), ::Opencellid.to_i_or_nil(attrs['mnc']), ::Opencellid.to_i_or_nil(attrs['mcc']),::Opencellid.to_i_or_nil(attrs['lac'])) result.lat = ::Opencellid.to_f_or_nil(attrs['lat']) result.lon = ::Opencellid.to_f_or_nil(attrs['lon']) result.range = ::Opencellid.to_i_or_nil(attrs['range']) result.no_of_samples= ::Opencellid.to_i_or_nil(attrs['nbSamples']) element.elements.each('measure') { |e| result.add_measure Measure.from_element e} result end |
Instance Method Details
#add_measure(measure) ⇒ Object
Adds a new measure to this cell does NOT result in an add_measure call being invoked on the Opencellid object
54 55 56 |
# File 'lib/opencellid/cell.rb', line 54 def add_measure(measure) @measures << measure end |
#has_measures? ⇒ bool
Indicates whether this cell contains measure objects
47 48 49 |
# File 'lib/opencellid/cell.rb', line 47 def has_measures? @measures.count > 0 end |
#to_lng_lat ⇒ Array
Returns an array containing the longitude and latitude of the cell, this method makes the Cell object to be compatible with mongoid_spacial gem
68 69 70 |
# File 'lib/opencellid/cell.rb', line 68 def to_lng_lat [lon, lat] end |
#to_query_hash ⇒ Hash
Helper function that transforms the parameters of this cell in a hash of query parameters to be used with the library cell querying functions
61 62 63 |
# File 'lib/opencellid/cell.rb', line 61 def to_query_hash {cellid: id, mnc: mnc, mcc: mcc, lac: lac}.delete_if {|_,v| v.nil?} end |