Class: Peck::Rails::Controller::Body
- Inherits:
-
Object
- Object
- Peck::Rails::Controller::Body
- Defined in:
- lib/peck_on_rails.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #document ⇒ Object
-
#initialize(response) ⇒ Body
constructor
A new instance of Body.
- #inspect ⇒ Object
- #json ⇒ Object
- #match_css?(query) ⇒ Boolean
- #match_xpath?(query) ⇒ Boolean
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
191 192 193 |
# File 'lib/peck_on_rails.rb', line 191 def blank? @response.body.blank? end |
#document ⇒ Object
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 |
#inspect ⇒ Object
195 196 197 |
# File 'lib/peck_on_rails.rb', line 195 def inspect "#<html body=\"#{@response.body}\">" end |
#json ⇒ Object
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
183 184 185 |
# File 'lib/peck_on_rails.rb', line 183 def match_css?(query) !document.css(query).empty? end |
#match_xpath?(query) ⇒ Boolean
187 188 189 |
# File 'lib/peck_on_rails.rb', line 187 def match_xpath?(query) !document.xpath(query).empty? end |