Class: Extractula::OEmbed::Response
- Inherits:
-
Object
- Object
- Extractula::OEmbed::Response
- Defined in:
- lib/extractula/oembed.rb
Constant Summary collapse
- FIELDS =
%w{ type version title author_name author_url provider_name provider_url cache_age thumbnail_url thumbnail_width thumbnail_height }
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #[](field) ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/extractula/oembed.rb', line 122 def initialize response @doc = ::JSON.parse(response) FIELDS.each { |field| instance_variable_set "@#{field}", @doc[field] } unless @type == 'link' @width = @doc['width'] @height = @doc['height'] if @type == 'photo' @url = @doc['url'] else @html = @doc['html'] end end def [](field) @doc[field] end end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
120 121 122 |
# File 'lib/extractula/oembed.rb', line 120 def height @height end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
120 121 122 |
# File 'lib/extractula/oembed.rb', line 120 def html @html end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
120 121 122 |
# File 'lib/extractula/oembed.rb', line 120 def url @url end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
120 121 122 |
# File 'lib/extractula/oembed.rb', line 120 def width @width end |
Instance Method Details
#[](field) ⇒ Object
135 136 137 |
# File 'lib/extractula/oembed.rb', line 135 def [](field) @doc[field] end |