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.



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

def initialize(response)
  @response = response
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


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

def blank?
  @response.body.blank?
end

#documentObject



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

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



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

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

#jsonObject



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

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)


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

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

#match_xpath?(query) ⇒ Boolean

Returns:

  • (Boolean)


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

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