Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/circle/art.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #filenames ⇒ Object
- #hashes ⇒ Object
-
#initialize(path: nil, text: nil, pattern: '') ⇒ Parser
constructor
TODO: support path to file.
- #urls ⇒ Object
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
#json ⇒ Object (readonly)
Returns the value of attribute json.
63 64 65 |
# File 'lib/circle/art.rb', line 63 def json @json end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
63 64 65 |
# File 'lib/circle/art.rb', line 63 def pattern @pattern end |
Instance Method Details
#filenames ⇒ Object
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 |
#hashes ⇒ Object
75 76 77 |
# File 'lib/circle/art.rb', line 75 def hashes @hashes ||= @json.select {|e| e["url"].split('/').last.match(pattern)} end |
#urls ⇒ Object
79 80 81 |
# File 'lib/circle/art.rb', line 79 def urls @urls ||= hashes.map{|e| e["url"]} end |