Class: Craig::Listing::Base

Inherits:
Object
  • Object
show all
Includes:
Node::HasImage, Node::HasMap, Node::Id, Node::Location, Node::PostedAt, Node::Title, Node::Url
Defined in:
lib/craig/listing.rb

Direct Known Subclasses

Community, ForSale, Gigs, Housing, Jobs, Personals, Resumes, Services

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node::HasMap

#has_map?

Methods included from Node::HasImage

#has_image?

Methods included from Node::Id

#id

Methods included from Node::Url

#url

Methods included from Node::Location

#location

Methods included from Node::PostedAt

#posted_at

Methods included from Node::Title

#title

Constructor Details

#initialize(dom) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/craig/listing.rb', line 6

def initialize(dom)
  @dom = dom
end

Instance Attribute Details

#domObject (readonly)

Returns the value of attribute dom.



4
5
6
# File 'lib/craig/listing.rb', line 4

def dom
  @dom
end

Instance Method Details

#listing_methodsArray

The available methods for this listing.

Returns:

  • (Array)


23
24
25
26
# File 'lib/craig/listing.rb', line 23

def listing_methods
  (self.class.instance_methods & Node.all_methods)
    .sort.reverse!
end

#to_hashObject



16
17
18
# File 'lib/craig/listing.rb', line 16

def to_hash
  Hash[listing_methods.map {|m| [m, send(m)] }]
end

#to_sObject



10
11
12
13
14
# File 'lib/craig/listing.rb', line 10

def to_s
  "{\n  " << to_hash.map do |key, value|
    ":#{key} => #{value.inspect}"
  end.join("\n  ") << "\n}"
end