Class: Nokogiri::HTML::Document

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

Overview

Instance Method Summary collapse

Instance Method Details

#get_the(search) ⇒ Object



162
163
164
# File 'lib/charles/document.rb', line 162

def get_the(search)
  self.search(search).first rescue nil
end

#match(queries = []) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/charles/document.rb', line 166

def match(queries = [])
  [].tap do |results|
    [*queries].each do |query|
      result = begin
        if query.is_a?(String)
          if el = self.search(query).first
            if el.name.downcase == "meta"
              el['content']
            else
              el.inner_text
            end
          end
        elsif query.is_a?(Array)
          query.last.call( self.search(query.first).first )
        end
      rescue
        nil
      end
      results << Charles::Misc.normalize_string(result) if result
    end
  end.compact
end