Class: Skeptick::Convert

Inherits:
Object
  • Object
show all
Defined in:
lib/skeptick/convert.rb,
lib/skeptick/sugar/compose.rb

Direct Known Subclasses

Compose

Constant Summary collapse

BINARY_PATH =
'convert'.freeze
DEFAULT_OUTPUT =
'miff:-'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Convert.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/skeptick/convert.rb', line 11

def initialize(context, *args, &blk)
  @context = context
  opts = args.last.is_a?(Hash) ? args.pop : {}

  @objects = [
    @beginning = BINARY_PATH.dup,
    @prepends  = setup_prepends,
    @subjects  = setup_subjects,
    @appends   = setup_appends,
    @ending    = opts.fetch(:to){ DEFAULT_OUTPUT }.dup
  ]

  args.each do |arg|
    subjects << if arg.is_a?(Convert)
      arg
    else
      Convert.new(@context).tap{ |c| c.subjects << arg }
    end
  end

  DslContext.new(self).instance_eval(&blk) if block_given?
end

Instance Attribute Details

#appendsObject (readonly)

Returns the value of attribute appends.



6
7
8
# File 'lib/skeptick/convert.rb', line 6

def appends
  @appends
end

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/skeptick/convert.rb', line 6

def context
  @context
end

#prependsObject (readonly)

Returns the value of attribute prepends.



6
7
8
# File 'lib/skeptick/convert.rb', line 6

def prepends
  @prepends
end

#subjectsObject (readonly)

Returns the value of attribute subjects.



6
7
8
# File 'lib/skeptick/convert.rb', line 6

def subjects
  @subjects
end

Instance Method Details

#&(other) ⇒ Object



30
31
32
33
34
# File 'lib/skeptick/sugar/compose.rb', line 30

def &(other)
  Compose.new(@context, :dstin, self, other).tap do |c|
    c.subjects << :alpha << 'Set'
  end
end

#*(other) ⇒ Object



22
23
24
# File 'lib/skeptick/sugar/compose.rb', line 22

def *(other)
  Compose.new(@context, :multiply, self, other)
end

#+(other) ⇒ Object



14
15
16
# File 'lib/skeptick/sugar/compose.rb', line 14

def +(other)
  Compose.new(@context, :over, self, other)
end

#-(other) ⇒ Object



18
19
20
# File 'lib/skeptick/sugar/compose.rb', line 18

def -(other)
  Compose.new(@context, :dstout, self, other)
end

#/(other) ⇒ Object



26
27
28
# File 'lib/skeptick/sugar/compose.rb', line 26

def /(other)
  Compose.new(@context, :divide, self, other)
end

#commandObject



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

def command; Command.new(shellwords) end

#inspectObject



36
# File 'lib/skeptick/convert.rb', line 36

def inspect; "#{self.class}(\"#{to_s}\")" end

#runObject



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

def run; command.run end

#shellwordsObject



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

def shellwords; tokens.map { |obj| token_to_str(obj) } end

#to_sObject



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

def to_s; shellwords.join(' ') end

#|(other) ⇒ Object



36
37
38
# File 'lib/skeptick/sugar/compose.rb', line 36

def |(other)
  Compose.new(@context, :dstover, self, other)
end