class DocumentScope
Public Class Methods
new(body)
click to toggle source
# File lib/document.rb, line 34 def initialize(body) @context = Nokogiri::HTML.parse(body) end
Public Instance Methods
[](value)
click to toggle source
# File lib/document.rb, line 50 def [](value) @context ? @context[value] : "" end
contents()
click to toggle source
# File lib/document.rb, line 54 def contents @context ? @context.text.gsub("\n","") : "" end
Also aliased as: text
count()
click to toggle source
# File lib/document.rb, line 59 def count @context ? @context.count : 0 end
each(&block)
click to toggle source
# File lib/document.rb, line 38 def each(&block) @context.each(&block) end
map(&block)
click to toggle source
# File lib/document.rb, line 42 def map(&block) @context.map(&block) end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/document.rb, line 5 def method_missing(m, *args, &block) if m.to_s =~ /^(.*?)_tags$/ tag_name = $1 @context = @context.search($1) if @context self elsif m.to_s =~ /^(.*?)_tag$/ tag_name = $1 @context = @context.at($1) if @context self elsif m.to_s =~ /^(.*?)_tags_with_(.*?)$/ tag_name = $1 attribute_name = $2 attribute_value = "=#{args[0]}" unless args[0].nil? selector = "#{tag_name}[#{attribute_name}#{attribute_value}]" @context = @context.search(selector) if @context self elsif m.to_s =~ /^(.*?)_tag_with_(.*?)$/ tag_name = $1 attribute_name = $2 attribute_value = "='#{args[0]}'" unless args[0].nil? selector = "#{tag_name}[#{attribute_name}#{attribute_value}]" @context = @context.at(selector) if @context self else super end end
select(&block)
click to toggle source
# File lib/document.rb, line 46 def select(&block) @context.select(&block) end
to_s()
click to toggle source
# File lib/document.rb, line 62 def to_s @context ? @context.to_s.gsub("\n","") : "" end