Class: FirefoxJson::Session::Window

Inherits:
Base
  • Object
show all
Defined in:
lib/firefox-json/session.rb

Overview

A collection of tabs, both current and previous

Instance Attribute Summary collapse

Attributes inherited from Base

#path

Instance Method Summary collapse

Methods inherited from Base

children, choose_for, #dump, #eql?, inherited, #inspect, mattr_accessor, #reload, required_key=, #save, set_collection

Constructor Details

#initialize(data, is_closed = false) ⇒ Window

Returns a new instance of Window.



221
222
223
224
# File 'lib/firefox-json/session.rb', line 221

def initialize data, is_closed = false
  @is_closed = is_closed
  setup data
end

Instance Attribute Details

#is_closedObject (readonly)

Returns the value of attribute is_closed.



218
219
220
# File 'lib/firefox-json/session.rb', line 218

def is_closed
  @is_closed
end

Instance Method Details

#by_domainObject



238
239
240
# File 'lib/firefox-json/session.rb', line 238

def by_domain
  tabs.map(&:selected_domain).reduce(Hash.new(0)) {|h,host| h[host]+=1; h}.sort_by {|_,v| -v}
end

#current_urlsObject



230
231
232
# File 'lib/firefox-json/session.rb', line 230

def current_urls
  tabs.map(&:selected_url)
end

#hashObject



226
227
228
# File 'lib/firefox-json/session.rb', line 226

def hash
  tabs.hash
end

#selected_titleObject



234
235
236
# File 'lib/firefox-json/session.rb', line 234

def selected_title
  selected.selected.title
end

#to_sObject



242
243
244
# File 'lib/firefox-json/session.rb', line 242

def to_s
  "#<FirefoxJson::Window#{' closed!' if is_closed} tabs=#{tabs.size}#{' closed='+closed_tabs.size.to_s if closed_tabs.size>0} selected=\"#{selected_title}\">"
end