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.
117 118 119 |
# File 'app/services/landable/tidy_service.rb', line 117 def initialize source @source = source end |
Instance Method Details
#body ⇒ Object
125 126 127 128 129 |
# File 'app/services/landable/tidy_service.rb', line 125 def body if match = @source.match(/<body(?: [^>]*)?>(.*)<\/body>/m) deindent match[1] end end |
#css ⇒ Object
137 138 139 140 141 |
# File 'app/services/landable/tidy_service.rb', line 137 def css links = head.try :scan, /<link [^>]*type=['"]text\/css['"][^>]*>/ styles = head.try :scan, /<style[^>]*>.*?<\/style>/m [links.to_a, styles.to_a].flatten.join("\n\n") end |
#head ⇒ Object
131 132 133 134 135 |
# File 'app/services/landable/tidy_service.rb', line 131 def head if match = @source.match(/<head>(.*)<\/head>/m) deindent match[1] end end |
#to_s ⇒ Object
121 122 123 |
# File 'app/services/landable/tidy_service.rb', line 121 def to_s @source end |