Class: Ogo::PageSource
- Inherits:
-
Object
- Object
- Ogo::PageSource
- Defined in:
- lib/ogo/page_source.rb
Instance Attribute Summary collapse
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(src, options = {}) ⇒ PageSource
constructor
A new instance of PageSource.
- #inspect ⇒ Object
- #parse ⇒ Object
- #parse! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(src, options = {}) ⇒ PageSource
Returns a new instance of PageSource.
6 7 8 9 10 |
# File 'lib/ogo/page_source.rb', line 6 def initialize(src, ={}) @src = src @url = [:url] @charset = [:charset] end |
Instance Attribute Details
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
4 5 6 |
# File 'lib/ogo/page_source.rb', line 4 def charset @charset end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/ogo/page_source.rb', line 4 def doc @doc end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
4 5 6 |
# File 'lib/ogo/page_source.rb', line 4 def src @src end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/ogo/page_source.rb', line 4 def url @url end |
Instance Method Details
#inspect ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ogo/page_source.rb', line 25 def inspect str = "<Ogo::PageSource:0x00#{'%x' % (self.object_id << 1)}\n" str << "url=\"#{url}\",\n" str << "charset=\"#{charset}\",\n" str << "src=\"#{src.to_s.truncate(100, omission: '...')}\",\n" str << "doc=#{doc.to_s.truncate(100, omission: '...')}\" >" str end |
#parse ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ogo/page_source.rb', line 12 def parse unless charset _doc = Nokogiri.parse(src.scrub) @charset = guess_encoding(_doc) end Nokogiri::HTML(src, nil, charset) end |
#parse! ⇒ Object
20 21 22 23 |
# File 'lib/ogo/page_source.rb', line 20 def parse! @doc = parse self end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/ogo/page_source.rb', line 34 def to_s inspect end |