Class: Stratify::Garmin::RssItemAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/stratify-garmin/rss_item_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ RssItemAdapter

Returns a new instance of RssItemAdapter.



8
9
10
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 8

def initialize(item)
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



6
7
8
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 6

def item
  @item
end

Instance Method Details

#activity_typeObject



12
13
14
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 12

def activity_type
  description_content_in_table_row(4)
end

#created_atObject



16
17
18
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 16

def created_at
  item.pubDate
end

#descriptionObject



20
21
22
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 20

def description
  description_as_nokogiri_doc.at_xpath('//table/tr[1]/td[1]').content
end

#distance_in_milesObject



24
25
26
27
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 24

def distance_in_miles
  distance_string = description_content_in_table_row(6)
  distance_string.to_f
end

#elevation_gain_in_feetObject



29
30
31
32
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 29

def elevation_gain_in_feet
  elevation_gain_string = description_content_in_table_row(8)
  elevation_gain_string.to_i
end

#event_typeObject



34
35
36
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 34

def event_type
  description_content_in_table_row(5)
end

#guidObject



38
39
40
41
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 38

def guid
  guid_url = item.guid
  guid_url.slice(/\d*$/) # parse the id out of the url ".../activity/12345678"
end

#starting_latitudeObject



43
44
45
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 43

def starting_latitude
  starting_location[:latitude]
end

#starting_longitudeObject



47
48
49
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 47

def starting_longitude
  starting_location[:longitude]
end

#time_in_secondsObject



51
52
53
54
55
56
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 51

def time_in_seconds
  time_string = description_content_in_table_row(7)
  time_components = time_string.split(':').map(&:to_i)
  hours, minutes, seconds = time_components[0], time_components[1], time_components[2]
  (hours * 3600) + (minutes * 60) + seconds
end

#titleObject



58
59
60
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 58

def title
  item.title
end

#usernameObject



62
63
64
# File 'lib/stratify-garmin/rss_item_adapter.rb', line 62

def username
  description_content_in_table_row(2)
end