Class: Landable::TidyService::Result
- Inherits:
-
Object
- Object
- Landable::TidyService::Result
- Defined in:
- app/services/landable/tidy_service.rb
Instance Method Summary collapse
- #body ⇒ Object
- #css ⇒ Object
- #head ⇒ Object
-
#initialize(source) ⇒ Result
constructor
A new instance of Result.
- #to_s ⇒ Object
Constructor Details
#initialize(source) ⇒ Result
Returns a new instance of Result.
112 113 114 |
# File 'app/services/landable/tidy_service.rb', line 112 def initialize(source) @source = source end |
Instance Method Details
#body ⇒ Object
120 121 122 123 124 |
# File 'app/services/landable/tidy_service.rb', line 120 def body match = @source.match(%r{<body(?: [^>]*)?>(.*)<\/body>}m) return unless match deindent match[1] end |
#css ⇒ Object
132 133 134 135 136 |
# File 'app/services/landable/tidy_service.rb', line 132 def css links = head.try :scan, %r{<link [^>]*type=['"]text\/css['"][^>]*>} styles = head.try :scan, %r{<style[^>]*>.*?<\/style>}m [links.to_a, styles.to_a].flatten.join("\n\n") end |
#head ⇒ Object
126 127 128 129 130 |
# File 'app/services/landable/tidy_service.rb', line 126 def head match = @source.match(%r{<head>(.*)<\/head>}m) return unless match deindent match[1] end |
#to_s ⇒ Object
116 117 118 |
# File 'app/services/landable/tidy_service.rb', line 116 def to_s @source end |