Class: SVGGVS::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/svggvs/session.rb

Constant Summary collapse

EXPORT_DEFAULTS =
{
  :poker => {
    :the_game_crafter => {
      :pdf_card_size => '750x1050',
      :pdf_dpi => 300,
      :png_export_width => 825
    }
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



8
9
10
11
# File 'lib/svggvs/session.rb', line 8

def initialize
  @index = 0
  @card_sheet_identifier = "Card Data"
end

Instance Attribute Details

#card_backObject

Returns the value of attribute card_back.



5
6
7
# File 'lib/svggvs/session.rb', line 5

def card_back
  @card_back
end

#card_sheet_identifierObject

Returns the value of attribute card_sheet_identifier.



6
7
8
# File 'lib/svggvs/session.rb', line 6

def card_sheet_identifier
  @card_sheet_identifier
end

#card_sizeObject

Returns the value of attribute card_size.



5
6
7
# File 'lib/svggvs/session.rb', line 5

def card_size
  @card_size
end

#individual_files_pathObject

Returns the value of attribute individual_files_path.



3
4
5
# File 'lib/svggvs/session.rb', line 3

def individual_files_path
  @individual_files_path
end

#on_card_finished(&block) ⇒ Object

Returns the value of attribute on_card_finished.



3
4
5
# File 'lib/svggvs/session.rb', line 3

def on_card_finished
  @on_card_finished
end

#pdf_card_sizeObject

Returns the value of attribute pdf_card_size.



4
5
6
# File 'lib/svggvs/session.rb', line 4

def pdf_card_size
  @pdf_card_size
end

#pdf_dpiObject

Returns the value of attribute pdf_dpi.



4
5
6
# File 'lib/svggvs/session.rb', line 4

def pdf_dpi
  @pdf_dpi
end

#pdf_targetObject

Returns the value of attribute pdf_target.



5
6
7
# File 'lib/svggvs/session.rb', line 5

def pdf_target
  @pdf_target
end

#png_export_widthObject

Returns the value of attribute png_export_width.



4
5
6
# File 'lib/svggvs/session.rb', line 4

def png_export_width
  @png_export_width
end

#png_files_pathObject

Returns the value of attribute png_files_path.



4
5
6
# File 'lib/svggvs/session.rb', line 4

def png_files_path
  @png_files_path
end

#post_read_dataObject

Returns the value of attribute post_read_data.



5
6
7
# File 'lib/svggvs/session.rb', line 5

def post_read_data
  @post_read_data
end

#prepend_pdfObject

Returns the value of attribute prepend_pdf.



6
7
8
# File 'lib/svggvs/session.rb', line 6

def prepend_pdf
  @prepend_pdf
end

#svg_merged_targetObject

Returns the value of attribute svg_merged_target.



3
4
5
# File 'lib/svggvs/session.rb', line 3

def svg_merged_target
  @svg_merged_target
end

#svg_sourceObject

Returns the value of attribute svg_source.



3
4
5
# File 'lib/svggvs/session.rb', line 3

def svg_source
  @svg_source
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/svggvs/session.rb', line 5

def target
  @target
end

Instance Method Details

#card_finished!Object



21
22
23
24
25
# File 'lib/svggvs/session.rb', line 21

def card_finished!
  @on_card_finished.call(@index) if @on_card_finished

  @index += 1
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



13
14
15
# File 'lib/svggvs/session.rb', line 13

def configure
  yield self
end

#data_source=(source) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/svggvs/session.rb', line 57

def data_source=(source)
  data_source = DataSource.new(source)

  settings_from_hash(data_source.settings)

  @process = proc do
    data_source.each_card(card_sheet_identifier) do |card|
      if !!@post_read_data
        @post_read_data.call(card)
      end

      with_new_target do |target|
        target.inject!
        target.active_layers = card[:active_layers]
        target.replacements = card[:replacements]
      end
    end
  end
end

#fileObject



31
32
33
# File 'lib/svggvs/session.rb', line 31

def file
  @file ||= SVGGVS::File.new(@svg_source)
end

#process(&block) ⇒ Object



17
18
19
# File 'lib/svggvs/session.rb', line 17

def process(&block)
  @process = block
end

#runObject



35
36
37
38
39
40
41
# File 'lib/svggvs/session.rb', line 35

def run
  if !!@card_size && !!@target
    settings_from_hash(EXPORT_DEFAULTS[@card_size.spunderscore.to_sym][@target.spunderscore.to_sym])
  end

  @process.call
end

#settings_from_hash(hash) ⇒ Object



43
44
45
46
47
# File 'lib/svggvs/session.rb', line 43

def settings_from_hash(hash)
  hash.each do |setting, value|
    self.send("#{setting}=", value)
  end
end

#with_new_targetObject



49
50
51
52
53
54
55
# File 'lib/svggvs/session.rb', line 49

def with_new_target
  file.with_new_target do |target|
    yield target
  end

  card_finished!
end