Class: Wagon::Household
- Inherits:
-
Object
- Object
- Wagon::Household
- Defined in:
- lib/wagon/household.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#image_path ⇒ Object
Returns the value of attribute image_path.
-
#members ⇒ Object
Returns the value of attribute members.
- #name ⇒ Object
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #has_image? ⇒ Boolean
- #image_data ⇒ Object
- #individual? ⇒ Boolean
-
#initialize(connection) ⇒ Household
constructor
A new instance of Household.
- #reversed_name ⇒ Object
Constructor Details
#initialize(connection) ⇒ Household
Returns a new instance of Household.
13 14 15 16 |
# File 'lib/wagon/household.rb', line 13 def initialize(connection) @members = [] @connection = connection end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def address @address end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/wagon/household.rb', line 9 def connection @connection end |
#image_path ⇒ Object
Returns the value of attribute image_path.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def image_path @image_path end |
#members ⇒ Object
Returns the value of attribute members.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def members @members end |
#name ⇒ Object
18 19 20 |
# File 'lib/wagon/household.rb', line 18 def name self.individual? ? "#{members.first.name} #{@name}" : "#{@name} Household" end |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def phone_number @phone_number end |
Class Method Details
.create_from_td(connection, td) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wagon/household.rb', line 46 def self.create_from_td(connection, td) Household.new(connection).instance_eval do name_element, phone_element, *member_elements = *td.search('table > tr > td.eventsource[width="45%"] > table > tr > td.eventsource') @address = Address.extract_from_string(td.search('table > tr > td.eventsource[width="25%"]').inner_text) @image_path = td.at('table > tr > td.eventsource[width="30%"] > img')['src'] rescue nil @name = name_element.inner_text @phone_number = PhoneNumber.extract_from_string(phone_element.inner_text) member_elements.each_slice(2) do |name_and_email| name, email = *name_and_email.collect { |element| element.inner_text.gsub(/\302\240/, '').strip() } @members << Member.new(self, name, email) end self end end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/wagon/household.rb', line 38 def <=>(other) if has_image? == other.has_image? reversed_name <=> other.reversed_name else has_image? ? -1 : 1 end end |
#has_image? ⇒ Boolean
30 31 32 |
# File 'lib/wagon/household.rb', line 30 def has_image? !image_path.to_s.empty? end |
#image_data ⇒ Object
34 35 36 |
# File 'lib/wagon/household.rb', line 34 def image_data @image_data ||= image_path.to_s.empty? ? "" : connection.get(image_path) end |
#individual? ⇒ Boolean
26 27 28 |
# File 'lib/wagon/household.rb', line 26 def individual? members.count == 1 end |
#reversed_name ⇒ Object
22 23 24 |
# File 'lib/wagon/household.rb', line 22 def reversed_name self.individual? ? "#{@name}, #{members.first.name}" : name end |