Class: Validifier::FlashMovie

Inherits:
Object
  • Object
show all
Defined in:
lib/validifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ FlashMovie

Returns a new instance of FlashMovie.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/validifier.rb', line 14

def initialize(source, options={})
  @source = source
  @width  = options[:width] || WIDTH
  @height = options[:height] || HEIGHT
  @codebase = options[:codebase] || 
  @classid = options[:classid] || 
  @params = options[:params] || {}
  @comment = options[:comment] || ""
  
  @coder = HTMLEntities.new
end

Instance Attribute Details

#classidObject

Returns the value of attribute classid.



12
13
14
# File 'lib/validifier.rb', line 12

def classid
  @classid
end

#codebaseObject

Returns the value of attribute codebase.



12
13
14
# File 'lib/validifier.rb', line 12

def codebase
  @codebase
end

#commentObject

Returns the value of attribute comment.



12
13
14
# File 'lib/validifier.rb', line 12

def comment
  @comment
end

#heightObject

Returns the value of attribute height.



12
13
14
# File 'lib/validifier.rb', line 12

def height
  @height
end

#paramsObject

Returns the value of attribute params.



12
13
14
# File 'lib/validifier.rb', line 12

def params
  @params
end

#sourceObject

Returns the value of attribute source.



12
13
14
# File 'lib/validifier.rb', line 12

def source
  @source
end

#widthObject

Returns the value of attribute width.



12
13
14
# File 'lib/validifier.rb', line 12

def width
  @width
end

Class Method Details

.from_source(html_str) ⇒ Object

Build a FlashMovie based on chunk of HTML (with object and/or embed code)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/validifier.rb', line 52

def from_source(html_str)
  html = Hpricot(html_str)
  if object = (html/:object).first
    movie = scrape_object(object)
  elsif embed = (html/:embed).first
    movie = scrape_embed(embed)
  else
    return nil
  end
  movie
end

.validify(html_str) ⇒ Object

Convert html to valid XHTML



65
66
67
# File 'lib/validifier.rb', line 65

def validify(html_str)
  FlashMovie.from_source(html_str).to_s
end

Instance Method Details

#clean(str) ⇒ Object

nodoc



27
28
29
# File 'lib/validifier.rb', line 27

def clean(str)
  @coder.encode(@coder.decode(str.to_s))
end

#to_sObject

The valid XHTML markup for this flash movie



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/validifier.rb', line 32

def to_s
  
  output = %Q{<!--[if !IE]> -->
  <object type="application/x-shockwave-flash" data="#{clean(source)}" width="#{clean(width)}" height="#{clean(height)}">
<!-- <![endif]-->
<!--[if IE]>
  <object classid="#{clean(classid)}" codebase="#{clean(codebase)}" width="#{clean(width)}" height="#{clean(height)}">
<param name="movie" value="#{clean(source)}" />
<!--><!-- #{comment} -->
}
  params ||= {}
  params.each do |name, value|
   output << %Q{    <param name="#{clean(name)}" value="#{clean(value)}" />\n}
  end
  output + "  </object>\n<!-- <![endif]-->"
end