Class: OpenGraphReader::Builder Private
- Inherits:
-
Object
- Object
- OpenGraphReader::Builder
- Defined in:
- lib/open_graph_reader/builder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
validate required, verticals
Convert a Parser::Graph into the right hierarchy of Objects attached to a Base.
Constant Summary collapse
- KNOWN_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Well-known types from
%w( website music.song music.album music.playlist music.radio_station video.movie video.episode video.tv_show video.other article book profile ).freeze
Instance Method Summary collapse
-
#base ⇒ Base
private
Build and return the base.
-
#initialize(graph, additional_namespaces = []) ⇒ Builder
constructor
private
Create a new builder.
Constructor Details
#initialize(graph, additional_namespaces = []) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new builder.
33 34 35 36 |
# File 'lib/open_graph_reader/builder.rb', line 33 def initialize graph, additional_namespaces=[] @graph = graph @additional_namespaces = additional_namespaces end |
Instance Method Details
#base ⇒ Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build and return the base.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/open_graph_reader/builder.rb', line 41 def base base = Base.new type = @graph.fetch 'og:type', 'website' validate_type type @graph.each do |property| root, *path, name = property.path base[root] ||= Object::Registry[root].new object = resolve base[root], root, path if object.respond_to? "#{name}s" # Collection # TODO collection = object.public_send "#{name}s" #TODO if Object::Registry.registered? property.fullname # of subobjects object = Object::Registry[property.fullname].new collection << object object.content = property.content else # of type collection << property.content end elsif Object::Registry.registered? property.fullname # Subobject object[name] ||= Object::Registry[property.fullname].new object[name].content = property.content else # Direct attribute object[name] = property.content end end base end |