Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/craig/tasks/update_cities.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



28
29
30
# File 'lib/craig/tasks/update_cities.rb', line 28

def initialize(node)
  @node = node
end

Instance Method Details

#aObject



31
32
33
# File 'lib/craig/tasks/update_cities.rb', line 31

def a
  @node.at_css("a")
end

#cityObject



40
41
42
# File 'lib/craig/tasks/update_cities.rb', line 40

def city
  a.text.strip.downcase
end

#city_compressedObject

“del rio / eagle pass” => “delrioeaglepass”



37
38
39
# File 'lib/craig/tasks/update_cities.rb', line 37

def city_compressed # "del rio / eagle pass" => "delrioeaglepass"
  city.gsub(/\W+/, "")
end

#city_underscoredObject

“del rio / eagle pass” => “del_rio_eagle_pass”



34
35
36
# File 'lib/craig/tasks/update_cities.rb', line 34

def city_underscored  # "del rio / eagle pass" => "del_rio_eagle_pass"
  city.gsub(/\W+/, " ").strip.gsub(/ /, "_")
end

#subdomainObject

austin.craigslist.org” => “austin”



43
44
45
# File 'lib/craig/tasks/update_cities.rb', line 43

def subdomain # "http://austin.craigslist.org" => "austin"
  URI.parse(a[:href]).host.split(".").first
end

#to_sObject



46
47
48
# File 'lib/craig/tasks/update_cities.rb', line 46

def to_s
  "'city' => #{city_compressed}, 'sub' => #{subdomain}"
end