Class: Dato::Local::FieldType::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/dato/local/field_type/video.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, thumbnail_url, title, width, height, provider, provider_url, provider_uid) ⇒ Video

Returns a new instance of Video.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dato/local/field_type/video.rb', line 29

def initialize(
  url,
  thumbnail_url,
  title,
  width,
  height,
  provider,
  provider_url,
  provider_uid
)
  @url            = url
  @thumbnail_url  = thumbnail_url
  @title          = title
  @width          = width
  @height         = height
  @provider       = provider
  @provider_url   = provider_url
  @provider_uid   = provider_uid
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



11
12
13
# File 'lib/dato/local/field_type/video.rb', line 11

def height
  @height
end

#providerObject (readonly)

Returns the value of attribute provider.



12
13
14
# File 'lib/dato/local/field_type/video.rb', line 12

def provider
  @provider
end

#provider_uidObject (readonly)

Returns the value of attribute provider_uid.



14
15
16
# File 'lib/dato/local/field_type/video.rb', line 14

def provider_uid
  @provider_uid
end

#provider_urlObject (readonly)

Returns the value of attribute provider_url.



13
14
15
# File 'lib/dato/local/field_type/video.rb', line 13

def provider_url
  @provider_url
end

#thumbnail_urlObject (readonly)

Returns the value of attribute thumbnail_url.



8
9
10
# File 'lib/dato/local/field_type/video.rb', line 8

def thumbnail_url
  @thumbnail_url
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/dato/local/field_type/video.rb', line 9

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/dato/local/field_type/video.rb', line 7

def url
  @url
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'lib/dato/local/field_type/video.rb', line 10

def width
  @width
end

Class Method Details

.parse(value, _repo) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dato/local/field_type/video.rb', line 16

def self.parse(value, _repo)
  value && new(
    value[:url],
    value[:thumbnail_url],
    value[:title],
    value[:width],
    value[:height],
    value[:provider],
    value[:provider_url],
    value[:provider_uid]
  )
end

Instance Method Details

#iframe_embed(width = self.width, height = self.height) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dato/local/field_type/video.rb', line 49

def iframe_embed(width = self.width, height = self.height)
  # rubocop:disable Metrics/LineLength
  if provider == 'youtube'
    %(<iframe width="#{width}" height="#{height}" src="//www.youtube.com/embed/#{provider_uid}?rel=0" frameborder="0" allowfullscreen></iframe>)
  elsif provider == 'vimeo'
    %(<iframe src="//player.vimeo.com/video/#{provider_uid}?title=0&amp;byline=0&amp;portrait=0" width="#{width}" height="#{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>)
  elsif provider == 'facebook'
    %(<iframe src="//www.facebook.com/plugins/video.php?href=#{url}&width=#{width}&show_text=false&height=#{height}" width="#{width}" height="#{height}" style="border:none;overflow:hidden;width:100%;" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media" allowFullScreen="true"></iframe>)
  end
  # rubocop:enable Metrics/LineLength
end

#to_hash(*_args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dato/local/field_type/video.rb', line 61

def to_hash(*_args)
  {
    url: url,
    thumbnail_url: thumbnail_url,
    title: title,
    width: width,
    height: height,
    provider: provider,
    provider_url: provider_url,
    provider_uid: provider_uid
  }
end