Class: ShuttleCli::Reader
- Inherits:
-
Object
- Object
- ShuttleCli::Reader
- Defined in:
- lib/shuttle_cli/reader.rb
Instance Attribute Summary collapse
-
#bookmarks ⇒ Object
Returns the value of attribute bookmarks.
Instance Method Summary collapse
- #bookmarks_json ⇒ Object
-
#initialize ⇒ Reader
constructor
A new instance of Reader.
- #json_file_content ⇒ Object
- #json_location ⇒ Object
- #load_bookmarks ⇒ Object
Constructor Details
#initialize ⇒ Reader
Returns a new instance of Reader.
5 6 7 8 |
# File 'lib/shuttle_cli/reader.rb', line 5 def initialize self.bookmarks = load_bookmarks self end |
Instance Attribute Details
#bookmarks ⇒ Object
Returns the value of attribute bookmarks.
3 4 5 |
# File 'lib/shuttle_cli/reader.rb', line 3 def bookmarks @bookmarks end |
Instance Method Details
#bookmarks_json ⇒ Object
34 35 36 |
# File 'lib/shuttle_cli/reader.rb', line 34 def bookmarks_json JSON.parse json_file_content end |
#json_file_content ⇒ Object
30 31 32 |
# File 'lib/shuttle_cli/reader.rb', line 30 def json_file_content File.open(json_location, "rb") {|f| f.read } end |
#json_location ⇒ Object
26 27 28 |
# File 'lib/shuttle_cli/reader.rb', line 26 def json_location open(ENV['HOME']+'/.shuttle.json') end |
#load_bookmarks ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/shuttle_cli/reader.rb', line 10 def load_bookmarks json = bookmarks_json.with_indifferent_access hosts = json[:hosts].flatten converted = hosts.map do |h| Bookmark.new_from_json h end # For now flatten all. converted.map do |b| if b.children b.children else b end end.flatten end |