Class: Opencellid::Measure
- Inherits:
-
Object
- Object
- Opencellid::Measure
- Defined in:
- lib/opencellid/measure.rb
Overview
A class which models the measurement of a cell position
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#signal ⇒ Object
Returns the value of attribute signal.
-
#taken_by ⇒ Object
Returns the value of attribute taken_by.
-
#taken_on ⇒ Object
Returns the value of attribute taken_on.
Class Method Summary collapse
-
.from_element(element) ⇒ Measure
Parses the given XML element extracting the information into the corresponding Measure object.
Instance Method Summary collapse
-
#initialize(lat, lon, taken_on = nil) ⇒ Measure
constructor
A new instance of Measure.
Constructor Details
#initialize(lat, lon, taken_on = nil) ⇒ Measure
Returns a new instance of Measure.
17 18 19 20 21 |
# File 'lib/opencellid/measure.rb', line 17 def initialize(lat, lon, taken_on = nil) @lat = lat @lon = lon @taken_on = taken_on end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def id @id end |
#lat ⇒ Object
Returns the value of attribute lat.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def lon @lon end |
#signal ⇒ Object
Returns the value of attribute signal.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def signal @signal end |
#taken_by ⇒ Object
Returns the value of attribute taken_by.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def taken_by @taken_by end |
#taken_on ⇒ Object
Returns the value of attribute taken_on.
12 13 14 |
# File 'lib/opencellid/measure.rb', line 12 def taken_on @taken_on end |
Class Method Details
.from_element(element) ⇒ Measure
Parses the given XML element extracting the information into the corresponding Measure object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opencellid/measure.rb', line 27 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 <measure>' unless element.name == 'measure' attrs = element.attributes date = attrs['takenOn'] date ||= attrs['measured_at'] measure = Measure.new(::Opencellid::to_f_or_nil(attrs['lat']),::Opencellid::to_f_or_nil(attrs['lon']), ::Opencellid::to_datetime_or_nil(date,DATE_FORMAT)) measure.id = ::Opencellid.to_i_or_nil(attrs['id']) measure.taken_by= attrs['takenBy'] measure.signal = ::Opencellid.to_i_or_nil(attrs['signal']) measure end |