Class: Vinery::Record
- Inherits:
-
Object
- Object
- Vinery::Record
- Defined in:
- lib/vinery/record.rb
Overview
Public: A Vine post. Contains attributes and helper methods for working with a specific post.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#share_url ⇒ Object
readonly
Returns the value of attribute share_url.
-
#thumbnail_url ⇒ Object
readonly
Returns the value of attribute thumbnail_url.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#venue ⇒ Object
readonly
Returns the value of attribute venue.
-
#video_url ⇒ Object
readonly
Returns the value of attribute video_url.
Instance Method Summary collapse
-
#embed_tag(type = :simple, html_attrs = {}) ⇒ Object
Public: Produces a HTML iframe embed tag.
-
#initialize(data) ⇒ Record
constructor
Public: Initializes a new Record instance.
-
#inspect ⇒ Object
Public: Produces a human-readable representation of the Record.
-
#to_h ⇒ Object
Public: Converts the Record into a Hash.
-
#to_json(*a) ⇒ Object
Public: Converts the Record into JSON.
Constructor Details
#initialize(data) ⇒ Record
Public: Initializes a new Record instance.
data - A Hash that contains the posting’s attributes. Typically this is
a record from a parsed JSON response.
Returns the new Vine instance.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vinery/record.rb', line 13 def initialize(data) @description = data["description"] @id = data["postId"] @raw = data @share_url = data["shareUrl"] @thumbnail_url = data["thumbnailUrl"] @user_id = data["userId"] @venue = data["venue_name"] @video_url = data["videoUrl"] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def id @id end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def raw @raw end |
#share_url ⇒ Object (readonly)
Returns the value of attribute share_url.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def share_url @share_url end |
#thumbnail_url ⇒ Object (readonly)
Returns the value of attribute thumbnail_url.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def thumbnail_url @thumbnail_url end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def user_id @user_id end |
#venue ⇒ Object (readonly)
Returns the value of attribute venue.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def venue @venue end |
#video_url ⇒ Object (readonly)
Returns the value of attribute video_url.
5 6 7 |
# File 'lib/vinery/record.rb', line 5 def video_url @video_url end |
Instance Method Details
#embed_tag(type = :simple, html_attrs = {}) ⇒ Object
Public: Produces a HTML iframe embed tag.
type - A Symbol that specifies the type of embed layout to display.
Possible types are :simple and :postcard (default: :simple).
If the type is not allowed, it will revert to :simple.
html_attrs - A Hash of HTML attributes for the iframe tag (default: {}).
Any keys with an underscore ("_") will be replaced with a
hyphen ("-").
Examples
record.embed_tag
# => '<iframe src=".../embed/simple"></iframe>'
record.embed_tag(:postcard)
# => '<iframe src=".../embed/postcard"></iframe>'
record.embed_tag(:simple, {
width: 600,
height: 600,
id: "vine-video",
class: "class1 class2",
data_foo: "bar"
})
# => '<iframe src="..." width="600" height="600" id="vine-video"
class="class1 class2" data-foo="bar"></iframe>'
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vinery/record.rb', line 75 def (type = :simple, html_attrs = {}) allowed_types = [:simple, :postcard] type = :simple unless allowed_types.include?(type) attrs = "" html_attrs = attrs.each do |attr, val| attrs << " #{attr.to_s.replace('_', '-')}=\"#{val}\"" end "<iframe src=\"#{@share_url}/embed/#{type}\"#{attrs}></iframe>" end |
#inspect ⇒ Object
Public: Produces a human-readable representation of the Record.
Returns the String representation of the Record.
45 46 47 |
# File 'lib/vinery/record.rb', line 45 def inspect "<#{self.class} @id=\"#{@id}\" @video_url=\"#{@video_url}\" @description=\"#{@description}\">" end |
#to_h ⇒ Object
Public: Converts the Record into a Hash.
Returns the String representation of the Record.
27 28 29 30 31 32 33 |
# File 'lib/vinery/record.rb', line 27 def to_h h = {} instance_variables.map { |iv| iv.to_s.gsub(/^@/, "") }.each do |attribute| h[attribute] = send(attribute) end h end |
#to_json(*a) ⇒ Object
Public: Converts the Record into JSON.
Returns the String raw JSON data of the record.
38 39 40 |
# File 'lib/vinery/record.rb', line 38 def to_json(*a) to_h.to_json(*a) end |