Class: Fetcher::Microdata

Inherits:
Object
  • Object
show all
Includes:
Discoverer::Writer, Virtus
Defined in:
lib/fetcher-microdata.rb,
lib/fetcher-microdata/review.rb,
lib/fetcher-microdata/version.rb,
lib/fetcher-microdata/person_user.rb,
lib/fetcher-microdata/article_small.rb,
lib/fetcher-microdata/user_comments.rb

Direct Known Subclasses

ArticleSmall, PersonUser, Review, UserComments

Defined Under Namespace

Classes: ArticleSmall, PersonUser, Review, UnknownSocialNetworkError, UserComments

Constant Summary collapse

VERSION =
"0.0.13"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arguments) ⇒ Microdata

Returns a new instance of Microdata.



10
11
12
13
14
15
16
17
# File 'lib/fetcher-microdata.rb', line 10

def initialize *arguments
  if arguments.first.is_a? Symbol
    social_network = arguments.shift
    self.attributes = coerce social_network, *arguments
  elsif arguments.first.is_a? Hash
    self.attributes = arguments.first
  end
end

Instance Attribute Details

#_typeObject (readonly)

Returns the value of attribute _type.



8
9
10
# File 'lib/fetcher-microdata.rb', line 8

def _type
  @_type
end

Instance Method Details

#coerce(social_network, *raw_data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fetcher-microdata.rb', line 19

def coerce social_network, *raw_data
  begin
    eval("::#{self.class}::#{social_network.to_s.capitalize}::Coercer").call *raw_data
  rescue NameError => e
    if e.message.include? "#{self.class}::#{social_network.to_s.capitalize}"
      raise UnknownSocialNetworkError, 
        "Couldn't find coertion algorithm for '#{social_network}' social network, please require 'fetcher-microdata-#{social_network}' in your project and make sure it has a #{self.class}::#{social_network.to_s.capitalize}::Coercer"
    else
      raise e
    end
  end
end