Class: Peck::Rails::Controller::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/peck_on_rails.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Body

Returns a new instance of Body.



164
165
166
# File 'lib/peck_on_rails.rb', line 164

def initialize(response)
  @response = response
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/peck_on_rails.rb', line 192

def blank?
  @response.body.blank?
end

#documentObject



168
169
170
171
172
173
174
# File 'lib/peck_on_rails.rb', line 168

def document
  if defined?(:Nokogiri)
    @document ||= Nokogiri::HTML.parse(@response.body)
  else
    raise RuntimeError, "Please install Nokogiri to use the CSS or Xpath matchers (gem install nokogiri)"
  end
end

#inspectObject



196
197
198
# File 'lib/peck_on_rails.rb', line 196

def inspect
  "#<html body=\"#{@response.body}\">"
end

#jsonObject



176
177
178
179
180
181
182
# File 'lib/peck_on_rails.rb', line 176

def json
  if defined?(:JSON)
    @json ||= JSON.parse(@response.body)
  else
    raise RuntimeError, "Please install a JSON gem to use the json accessor (gem install json)"
  end
end

#match_css?(query) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/peck_on_rails.rb', line 184

def match_css?(query)
  !document.css(query).empty?
end

#match_xpath?(query) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/peck_on_rails.rb', line 188

def match_xpath?(query)
  !document.xpath(query).empty?
end