Class: ActiveWorksheet::Base

Inherits:
OpenStruct
  • Object
show all
Extended by:
ThreadsafeAttributes
Defined in:
lib/active_worksheet/base.rb

Class Method Summary collapse

Class Method Details

.adapterObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/active_worksheet/base.rb', line 35

def adapter
  if is_source_local?
    ActiveWorksheet::Adapters::FileAdapter.new(source: File.expand_path(source))
  else
    ActiveWorksheet::Adapters::GoogleSheetsAdapter.new(
      source: source,
      authorization: authorization
    )
  end
end

.allObject



13
14
15
16
17
# File 'lib/active_worksheet/base.rb', line 13

def all
  adapter.all.map do |row|
    new(row)
  end
end

.countObject



31
32
33
# File 'lib/active_worksheet/base.rb', line 31

def count
  adapter.count
end

.find(index) ⇒ Object



19
20
21
# File 'lib/active_worksheet/base.rb', line 19

def find(index)
  new(adapter.find(index))
end

.firstObject



23
24
25
# File 'lib/active_worksheet/base.rb', line 23

def first
  new(adapter.first)
end

.is_source_local?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/active_worksheet/base.rb', line 46

def is_source_local?
  self.source.is_a?(File) || File.exists?(File.expand_path(self.source))
end

.is_source_remote?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/active_worksheet/base.rb', line 50

def is_source_remote?
  !is_source_local?
end

.lastObject



27
28
29
# File 'lib/active_worksheet/base.rb', line 27

def last
  new(adapter.last)
end