Class: HyperNavigator::Node
- Inherits:
-
Object
- Object
- HyperNavigator::Node
- Defined in:
- lib/hyper_navigator/node.rb
Constant Summary collapse
- IGNORE_REFS =
["self", "up", "next", "prev"]
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#descendants ⇒ Object
Returns the value of attribute descendants.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #flatten_branch ⇒ Object
-
#initialize(rel, href, headers = {}, depth = nil) ⇒ Node
constructor
A new instance of Node.
- #links ⇒ Object
Constructor Details
#initialize(rel, href, headers = {}, depth = nil) ⇒ Node
Returns a new instance of Node.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hyper_navigator/node.rb', line 96 def initialize(rel, href, headers={}, depth=nil) @rel = rel @href = href @headers = headers @descendants = [] @depth = depth if href @response = HyperNavigator.get(href, headers) raise RuntimeError, @response unless @response.code =~ /^2..$/ end end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
94 95 96 |
# File 'lib/hyper_navigator/node.rb', line 94 def depth @depth end |
#descendants ⇒ Object
Returns the value of attribute descendants.
94 95 96 |
# File 'lib/hyper_navigator/node.rb', line 94 def descendants @descendants end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
93 94 95 |
# File 'lib/hyper_navigator/node.rb', line 93 def href @href end |
#rel ⇒ Object (readonly)
Returns the value of attribute rel.
93 94 95 |
# File 'lib/hyper_navigator/node.rb', line 93 def rel @rel end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
93 94 95 |
# File 'lib/hyper_navigator/node.rb', line 93 def response @response end |
Instance Method Details
#flatten_branch ⇒ Object
118 119 120 |
# File 'lib/hyper_navigator/node.rb', line 118 def flatten_branch descendants + descendants.flat_map { | d| d.flatten_branch } end |
#links ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/hyper_navigator/node.rb', line 108 def links @cached_links ||= begin json = JSON.parse(@response.body) rescue nil return [] unless json json["links"].reject do |i| IGNORE_REFS.any? { |r| r == i["rel"] } end end end |