Class: Spiral::DisplayData
- Inherits:
-
Object
- Object
- Spiral::DisplayData
- Defined in:
- lib/spiral/display_data.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #content_key ⇒ Object
- #height ⇒ Object
-
#initialize(title, local, chm) ⇒ DisplayData
constructor
A new instance of DisplayData.
- #retrieve ⇒ Object
- #trim(html, id) ⇒ Object
Constructor Details
#initialize(title, local, chm) ⇒ DisplayData
Returns a new instance of DisplayData.
5 6 7 8 9 |
# File 'lib/spiral/display_data.rb', line 5 def initialize(title, local, chm) @title = title @local = local @chm = chm end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/spiral/display_data.rb', line 3 def content @content end |
#local ⇒ Object (readonly)
Returns the value of attribute local.
2 3 4 |
# File 'lib/spiral/display_data.rb', line 2 def local @local end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
2 3 4 |
# File 'lib/spiral/display_data.rb', line 2 def title @title end |
Instance Method Details
#available? ⇒ Boolean
39 40 41 |
# File 'lib/spiral/display_data.rb', line 39 def available? !!@content end |
#content_key ⇒ Object
11 12 13 |
# File 'lib/spiral/display_data.rb', line 11 def content_key [@chm, @local].hash end |
#height ⇒ Object
43 44 45 |
# File 'lib/spiral/display_data.rb', line 43 def height @content.lines.size end |
#retrieve ⇒ Object
32 33 34 35 36 37 |
# File 'lib/spiral/display_data.rb', line 32 def retrieve id = @local.split("#")[1] html = @chm.retrieve_object("/#{@local.gsub(/#.*/, '')}") rescue "[Error]" html = trim(html, id) if id @content = ::Spiral::Renderer::W3m.new.render(html, :cols => $stdout.winsize.last) end |
#trim(html, id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spiral/display_data.rb', line 15 def trim(html, id) doc = Nokogiri::XML.parse html e = doc.at_css("##{id}") p = nil begin p = e.parent rescue nil ep = e.previous rescue nil while e = ep ep = e.previous e.remove end end while e = p doc.to_s end |