Class: Opencellid::Measure

Inherits:
Object
  • Object
show all
Defined in:
lib/opencellid/measure.rb

Overview

A class which models the measurement of a cell position

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat, lon, taken_on = nil) ⇒ Measure

Returns a new instance of Measure.

Parameters:

  • lat (Float)

    the latitude of the position measured

  • lon (Float)

    the longitude of the position measured

  • taken_on (DateTime) (defaults to: nil)

    the date/time information at which the measurement was taken



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

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/opencellid/measure.rb', line 12

def id
  @id
end

#latObject

Returns the value of attribute lat.



12
13
14
# File 'lib/opencellid/measure.rb', line 12

def lat
  @lat
end

#lonObject

Returns the value of attribute lon.



12
13
14
# File 'lib/opencellid/measure.rb', line 12

def lon
  @lon
end

#signalObject

Returns the value of attribute signal.



12
13
14
# File 'lib/opencellid/measure.rb', line 12

def signal
  @signal
end

#taken_byObject

Returns the value of attribute taken_by.



12
13
14
# File 'lib/opencellid/measure.rb', line 12

def taken_by
  @taken_by
end

#taken_onObject

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

Parameters:

  • element (REXML::Element)

    the XML element containing the representation of the measurement

Returns:

  • (Measure)

    the Measure object obtained by parsing the XML

Raises:

  • (ArgumentError)


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