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.
164 165 166 |
# File 'lib/peck_on_rails.rb', line 164 def initialize(response) @response = response end |
Instance Method Details
#blank? ⇒ Boolean
192 193 194 |
# File 'lib/peck_on_rails.rb', line 192 def blank? @response.body.blank? end |
#document ⇒ Object
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 |
#inspect ⇒ Object
196 197 198 |
# File 'lib/peck_on_rails.rb', line 196 def inspect "#<html body=\"#{@response.body}\">" end |
#json ⇒ Object
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
184 185 186 |
# File 'lib/peck_on_rails.rb', line 184 def match_css?(query) !document.css(query).empty? end |
#match_xpath?(query) ⇒ Boolean
188 189 190 |
# File 'lib/peck_on_rails.rb', line 188 def match_xpath?(query) !document.xpath(query).empty? end |