Class: Gattica::Account
- Inherits:
-
Object
- Object
- Gattica::Account
- Includes:
- Convertible
- Defined in:
- lib/gattica/account.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#account_name ⇒ Object
readonly
Returns the value of attribute account_name.
-
#goals ⇒ Object
readonly
Returns the value of attribute goals.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#profile_id ⇒ Object
readonly
Returns the value of attribute profile_id.
-
#table_id ⇒ Object
readonly
Returns the value of attribute table_id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
-
#web_property_id ⇒ Object
readonly
Returns the value of attribute web_property_id.
Instance Method Summary collapse
- #find_account_id(xml) ⇒ Object
- #find_account_name(xml) ⇒ Object
- #find_profile_id(xml) ⇒ Object
-
#initialize(xml) ⇒ Account
constructor
A new instance of Account.
- #set_account_name(account_feed_entry) ⇒ Object
- #set_goals(goals_feed_entry) ⇒ Object
- #xpath_value(xml, xpath) ⇒ Object
Methods included from Convertible
#to_h, #to_query, #to_s, #to_xml
Constructor Details
#initialize(xml) ⇒ Account
Returns a new instance of Account.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gattica/account.rb', line 8 def initialize(xml) @id = xml.at("link[@rel='self']").attributes['href'] @updated = DateTime.parse(xml.at(:updated).inner_html) @account_id = find_account_id(xml) @title = xpath_value(xml, "dxp:property[@name='ga:profileName']") @table_id = xpath_value(xml, "dxp:property[@name='dxp:tableId']") @profile_id = find_profile_id(xml) @web_property_id = xpath_value(xml, "dxp:property[@name='ga:webPropertyId']") @goals = [] end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def account_id @account_id end |
#account_name ⇒ Object (readonly)
Returns the value of attribute account_name.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def account_name @account_name end |
#goals ⇒ Object (readonly)
Returns the value of attribute goals.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def goals @goals end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def id @id end |
#profile_id ⇒ Object (readonly)
Returns the value of attribute profile_id.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def profile_id @profile_id end |
#table_id ⇒ Object (readonly)
Returns the value of attribute table_id.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def table_id @table_id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def title @title end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def updated @updated end |
#web_property_id ⇒ Object (readonly)
Returns the value of attribute web_property_id.
5 6 7 |
# File 'lib/gattica/account.rb', line 5 def web_property_id @web_property_id end |
Instance Method Details
#find_account_id(xml) ⇒ Object
24 25 26 |
# File 'lib/gattica/account.rb', line 24 def find_account_id(xml) xml.at("dxp:property[@name='ga:accountId']").attributes['value'].to_i end |
#find_account_name(xml) ⇒ Object
28 29 30 |
# File 'lib/gattica/account.rb', line 28 def find_account_name(xml) xml.at("dxp:property[@name='ga:accountName']").attributes['value'] end |
#find_profile_id(xml) ⇒ Object
32 33 34 |
# File 'lib/gattica/account.rb', line 32 def find_profile_id(xml) xml.at("dxp:property[@name='ga:profileId']").attributes['value'].to_i end |
#set_account_name(account_feed_entry) ⇒ Object
36 37 38 39 40 |
# File 'lib/gattica/account.rb', line 36 def set_account_name(account_feed_entry) if @account_id == find_account_id(account_feed_entry) @account_name = find_account_name(account_feed_entry) end end |
#set_goals(goals_feed_entry) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gattica/account.rb', line 42 def set_goals(goals_feed_entry) if @profile_id == find_profile_id(goals_feed_entry) goal = goals_feed_entry.search('ga:goal').first @goals.push({ :active => goal.attributes['active'], :name => goal.attributes['name'], :number => goal.attributes['number'].to_i, :value => goal.attributes['value'].to_f }) end end |
#xpath_value(xml, xpath) ⇒ Object
20 21 22 |
# File 'lib/gattica/account.rb', line 20 def xpath_value(xml, xpath) xml.at(xpath).attributes['value'] end |