Class: Landable::TidyService::Result

Inherits:
Object
  • Object
show all
Defined in:
app/services/landable/tidy_service.rb

Instance Method Summary collapse

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

#bodyObject



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

#cssObject



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

#headObject



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_sObject



116
117
118
# File 'app/services/landable/tidy_service.rb', line 116

def to_s
  @source
end