Class: Peck::Rails::Controller::Body
- Inherits:
-
Object
- Object
- Peck::Rails::Controller::Body
- Defined in:
- lib/peck_on_rails/controller.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.
116 117 118 |
# File 'lib/peck_on_rails/controller.rb', line 116 def initialize(response) @response = response end |
Instance Method Details
#blank? ⇒ Boolean
144 145 146 |
# File 'lib/peck_on_rails/controller.rb', line 144 def blank? @response.body.blank? end |
#document ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/peck_on_rails/controller.rb', line 120 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
148 149 150 |
# File 'lib/peck_on_rails/controller.rb', line 148 def inspect "#<html body=\"#{@response.body}\">" end |
#json ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/peck_on_rails/controller.rb', line 128 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
136 137 138 |
# File 'lib/peck_on_rails/controller.rb', line 136 def match_css?(query) !document.css(query).empty? end |
#match_xpath?(query) ⇒ Boolean
140 141 142 |
# File 'lib/peck_on_rails/controller.rb', line 140 def match_xpath?(query) !document.xpath(query).empty? end |