class HyperNavigator::Node
Constants
- IGNORE_REFS
Attributes
depth[RW]
descendants[RW]
href[R]
rel[R]
response[R]
Public Class Methods
new(rel, href, headers={}, depth=nil)
click to toggle source
# 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
Public Instance Methods
flatten_branch()
click to toggle source
# File lib/hyper_navigator/node.rb, line 118 def flatten_branch descendants + descendants.flat_map { | d| d.flatten_branch } end
links()
click to toggle source
# 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