Class: ShuttleCli::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/shuttle_cli/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

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

#bookmarksObject

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_jsonObject



34
35
36
# File 'lib/shuttle_cli/reader.rb', line 34

def bookmarks_json
  JSON.parse json_file_content
end

#json_file_contentObject



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_locationObject



26
27
28
# File 'lib/shuttle_cli/reader.rb', line 26

def json_location
  open(ENV['HOME']+'/.shuttle.json')
end

#load_bookmarksObject



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