Class: Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/circle/art.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, text: nil, pattern: '') ⇒ Parser

TODO: support path to file



66
67
68
69
70
71
72
73
# File 'lib/circle/art.rb', line 66

def initialize(path: nil, text: nil, pattern: '')
  if path
    text = File.read(path)
  end

  @json = JSON.parse(text)
  @pattern = pattern
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



63
64
65
# File 'lib/circle/art.rb', line 63

def json
  @json
end

#patternObject (readonly)

Returns the value of attribute pattern.



63
64
65
# File 'lib/circle/art.rb', line 63

def pattern
  @pattern
end

Instance Method Details

#filenamesObject



83
84
85
86
87
# File 'lib/circle/art.rb', line 83

def filenames
  @filenames ||= urls.map.with_index do |e, index|
    "#{hashes[index]['node_index']}-" + e.split('/').last
  end
end

#hashesObject



75
76
77
# File 'lib/circle/art.rb', line 75

def hashes
  @hashes ||= @json.select {|e| e["url"].split('/').last.match(pattern)}
end

#urlsObject



79
80
81
# File 'lib/circle/art.rb', line 79

def urls
  @urls ||= hashes.map{|e| e["url"]}
end