Class: MarkdownVideos::Services::ServiceBase
- Inherits:
-
Object
- Object
- MarkdownVideos::Services::ServiceBase
- Defined in:
- lib/markdown_videos/services/service_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alt_text ⇒ String
Escaped alternative text given through markdown syntax.
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#markdown_url ⇒ Object
Returns the value of attribute markdown_url.
-
#markdown_url_data ⇒ MatchData
Match data from matching URL to service regexp.
-
#resource_id ⇒ String
Resource ID of the service resource rendered base on given URL.
-
#width ⇒ Object
Returns the value of attribute width.
-
#wrapper ⇒ Object
Returns the value of attribute wrapper.
Class Method Summary collapse
-
.regexp ⇒ Object
URL matcher.
- .support(markdown_url) ⇒ Object
Instance Method Summary collapse
-
#html_attributes ⇒ Hash
Default set of HTML attributes for default iframe element.
-
#html_dom_properties ⇒ String
Renders the set of HTML attributes.
-
#initialize(alt_text, markdown_url, options) ⇒ ServiceBase
constructor
A new instance of ServiceBase.
- #render ⇒ Object
-
#service_url ⇒ String
Service URL to be consumed by #to_html.
-
#to_html ⇒ Object
Default HTML rendering.
-
#url ⇒ Object
URL to be consumed by #to_html.
-
#url_parameters ⇒ Array<Symbol>
List of authorized url parameters.
Constructor Details
#initialize(alt_text, markdown_url, options) ⇒ ServiceBase
Returns a new instance of ServiceBase.
25 26 27 28 29 |
# File 'lib/markdown_videos/services/service_base.rb', line 25 def initialize(alt_text, markdown_url, ) @alt_text = alt_text @markdown_url = markdown_url.strip .each { |option, value| self.send("#{option}=", value) } end |
Instance Attribute Details
#alt_text ⇒ String
Returns escaped alternative text given through markdown syntax.
52 53 54 |
# File 'lib/markdown_videos/services/service_base.rb', line 52 def alt_text @alt_text end |
#class_name ⇒ Object
Returns the value of attribute class_name.
6 7 8 |
# File 'lib/markdown_videos/services/service_base.rb', line 6 def class_name @class_name end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/markdown_videos/services/service_base.rb', line 6 def height @height end |
#markdown_url ⇒ Object
Returns the value of attribute markdown_url.
6 7 8 |
# File 'lib/markdown_videos/services/service_base.rb', line 6 def markdown_url @markdown_url end |
#markdown_url_data ⇒ MatchData
Returns match data from matching URL to service regexp.
62 63 64 |
# File 'lib/markdown_videos/services/service_base.rb', line 62 def markdown_url_data @markdown_url_data end |
#resource_id ⇒ String
Returns resource ID of the service resource rendered base on given URL.
57 58 59 |
# File 'lib/markdown_videos/services/service_base.rb', line 57 def resource_id @resource_id end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/markdown_videos/services/service_base.rb', line 6 def width @width end |
#wrapper ⇒ Object
Returns the value of attribute wrapper.
6 7 8 |
# File 'lib/markdown_videos/services/service_base.rb', line 6 def wrapper @wrapper end |
Class Method Details
.regexp ⇒ Object
URL matcher
20 21 22 |
# File 'lib/markdown_videos/services/service_base.rb', line 20 def self.regexp raise NotImplementedError "#{self.class} should implement #regexp method" end |
.support(markdown_url) ⇒ Object
15 16 17 |
# File 'lib/markdown_videos/services/service_base.rb', line 15 def self.support(markdown_url) markdown_url =~ regexp end |
Instance Method Details
#html_attributes ⇒ Hash
Default set of HTML attributes for default iframe element
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/markdown_videos/services/service_base.rb', line 94 def html_attributes { title: alt_text, src: service_url, width: width, height: height, class: class_name, frameborder: "0", webkitallowfullscreen: true, mozallowfullscreen: true, allowfullscreen: true } end |
#html_dom_properties ⇒ String
Renders the set of HTML attributes
87 88 89 |
# File 'lib/markdown_videos/services/service_base.rb', line 87 def html_dom_properties html_attributes.map { |k, v| render_param(k, v) }.compact.join(" ") end |
#render ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/markdown_videos/services/service_base.rb', line 108 def render if wrapper sprintf(wrapper, to_html) else to_html end end |
#service_url ⇒ String
Returns service URL to be consumed by #to_html.
67 68 69 70 71 72 73 74 75 |
# File 'lib/markdown_videos/services/service_base.rb', line 67 def service_url given_url = Addressable::URI.parse(markdown_url) given_url_parameters = given_url.query_values || {} given_url_parameters.select! { |attribute, value| url_parameters.include?(attribute.to_sym) && (!value.nil? || !value.empty?) } service_url = Addressable::URI.parse(url) service_url.query_values = given_url_parameters unless given_url_parameters.nil? || given_url_parameters.empty? service_url.to_s end |
#to_html ⇒ Object
Default HTML rendering
80 81 82 |
# File 'lib/markdown_videos/services/service_base.rb', line 80 def to_html "<iframe #{html_dom_properties}></iframe>" end |
#url ⇒ Object
URL to be consumed by #to_html
32 33 34 |
# File 'lib/markdown_videos/services/service_base.rb', line 32 def url raise NotImplementedError "#{self.class} should implement #url method" end |
#url_parameters ⇒ Array<Symbol>
List of authorized url parameters
39 40 41 |
# File 'lib/markdown_videos/services/service_base.rb', line 39 def url_parameters [] end |