Class: Wagon::Household
- Inherits:
-
Object
- Object
- Wagon::Household
- Defined in:
- lib/wagon/household.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#image_data ⇒ Object
readonly
Returns the value of attribute image_data.
-
#image_path ⇒ Object
readonly
Returns the value of attribute image_path.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #has_image? ⇒ Boolean
- #individual? ⇒ Boolean
-
#initialize(connection, name, address, phone_number, image_path, members) ⇒ Household
constructor
A new instance of Household.
- #name ⇒ Object
- #reversed_name ⇒ Object
Constructor Details
#initialize(connection, name, address, phone_number, image_path, members) ⇒ Household
Returns a new instance of Household.
13 14 15 16 17 18 19 20 21 |
# File 'lib/wagon/household.rb', line 13 def initialize(connection, name, address, phone_number, image_path, members) @connection, @name, @address, @phone_number, @image_path, @members = connection, name, address, phone_number, image_path, members if has_image? @image_data = Future(image_path) do |image_path| @connection.get(image_path) end end end |
Instance Attribute Details
#address ⇒ Object (readonly)
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.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def connection @connection end |
#image_data ⇒ Object (readonly)
Returns the value of attribute image_data.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def image_data @image_data end |
#image_path ⇒ Object (readonly)
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 (readonly)
Returns the value of attribute members.
11 12 13 |
# File 'lib/wagon/household.rb', line 11 def members @members end |
#phone_number ⇒ Object (readonly)
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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wagon/household.rb', line 47 def self.create_from_td(connection, td) 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 phone_number = PhoneNumber.extract_from_string(phone_element.inner_text) members = [] 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.new(connection, name_element.inner_text, address, phone_number, image_path, members) end |
Instance Method Details
#<=>(other) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/wagon/household.rb', line 39 def <=>(other) if has_image? == other.has_image? reversed_name <=> other.reversed_name else has_image? ? -1 : 1 end end |
#has_image? ⇒ Boolean
35 36 37 |
# File 'lib/wagon/household.rb', line 35 def has_image? !image_path.to_s.empty? end |
#individual? ⇒ Boolean
31 32 33 |
# File 'lib/wagon/household.rb', line 31 def individual? members.count == 1 end |
#name ⇒ Object
23 24 25 |
# File 'lib/wagon/household.rb', line 23 def name self.individual? ? "#{members.first.name} #{@name}" : "#{@name} Household" end |
#reversed_name ⇒ Object
27 28 29 |
# File 'lib/wagon/household.rb', line 27 def reversed_name self.individual? ? "#{@name}, #{members.first.name}" : name end |