Class: Skeptick::Convert

Inherits:
Object
  • Object
show all
Includes:
Skeptick::Command::Executable, Sugar::Composition::Helper, Sugar::Composition::Operators
Defined in:
lib/skeptick/convert.rb,
lib/skeptick/sugar/composition.rb,
lib/skeptick/sugar/composition.rb,
lib/skeptick/convert/dsl_context.rb

Defined Under Namespace

Classes: DslContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sugar::Composition::Operators

#&, #*, #+, #-, #/, #|

Methods included from Sugar::Composition::Helper

#compose

Methods included from Skeptick::Command::Executable

#command, #execute

Constructor Details

#initialize(context, *args, &blk) ⇒ Convert



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/skeptick/convert.rb', line 13

def initialize(context, *args, &blk)
  @context = context
  @options = Helper.extract_options!(args)
  @args    = args.map {|a| Image.new(@context, a)}
  @block   = blk
  @to      = parse_pipe(@options[:to])
  @inner   = false

  @beginning = nil
  @ending    = nil
  @prepends  = []
  @appends   = []

  reset
end

Instance Attribute Details

#appendsObject

Returns the value of attribute appends.



11
12
13
# File 'lib/skeptick/convert.rb', line 11

def appends
  @appends
end

#prependsObject

Returns the value of attribute prepends.



11
12
13
# File 'lib/skeptick/convert.rb', line 11

def prepends
  @prepends
end

Instance Method Details

#append(*args) ⇒ Object



33
34
35
# File 'lib/skeptick/convert.rb', line 33

def append(*args)
  @appends << Helper.process_args(*args)
end

#become_innerObject



66
67
68
69
# File 'lib/skeptick/convert.rb', line 66

def become_inner
  @inner = true
  self
end

#convert(*args, &blk) ⇒ Object



44
45
46
47
48
# File 'lib/skeptick/convert.rb', line 44

def convert(*args, &blk)
  Convert.new(@context, *args, &blk).tap do |c_obj|
    @objects << Image.new(@context, c_obj)
  end
end

#destination=(to) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/skeptick/convert.rb', line 54

def destination=(to)
  if inner?
    raise 'cannot assign output to parentheses-wrapped image conversion'
  else
    @to = to
  end
end

#image(obj = nil, &blk) ⇒ Object



50
51
52
# File 'lib/skeptick/convert.rb', line 50

def image(obj = nil, &blk)
  @objects << Image.new(@context, obj, &blk)
end

#inspectObject



83
84
85
# File 'lib/skeptick/convert.rb', line 83

def inspect
  "Skeptick::Convert(#{to_s})"
end

#partsObject



71
72
73
74
75
76
77
# File 'lib/skeptick/convert.rb', line 71

def parts
  reset
  @objects = []
  DslContext.new(self).instance_eval(&@block) if @block
  wrap
  [@beginning, *@prepends, *@args, *@objects, *@appends, @ending].compact
end

#piping?Boolean



62
63
64
# File 'lib/skeptick/convert.rb', line 62

def piping?
  !inner? && parts.last == Chain::PIPE
end

#prepend(*args) ⇒ Object



29
30
31
# File 'lib/skeptick/convert.rb', line 29

def prepend(*args)
  @prepends << Helper.process_args(*args)
end

#process_method_missing(*args, &blk) ⇒ Object



87
88
89
# File 'lib/skeptick/convert.rb', line 87

def process_method_missing(*args, &blk)
  @context.send(*args, &blk)
end

#set(*args) ⇒ Object Also known as: apply, with



37
38
39
# File 'lib/skeptick/convert.rb', line 37

def set(*args)
  @objects << Helper.process_args(*args)
end

#to_sObject



79
80
81
# File 'lib/skeptick/convert.rb', line 79

def to_s
  parts.join(' ')
end