Class: Conv::ConvItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ ConvItem

Returns a new instance of ConvItem.



132
133
134
135
136
137
# File 'lib/ffc.rb', line 132

def initialize **params
  Config.load_and_set_settings(Dir.home + ".conv")
  @type |= :convert
  @package_manager = Settings.package_manager
  params.each{|k,v| self.send("#{k}=", v) if self.methods.include?(k)}
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



130
131
132
# File 'lib/ffc.rb', line 130

def command
  @command
end

#inputObject

Returns the value of attribute input.



130
131
132
# File 'lib/ffc.rb', line 130

def input
  @input
end

#input_pathObject

Returns the value of attribute input_path.



130
131
132
# File 'lib/ffc.rb', line 130

def input_path
  @input_path
end

#langObject

Returns the value of attribute lang.



130
131
132
# File 'lib/ffc.rb', line 130

def lang
  @lang
end

#last_accessObject

Returns the value of attribute last_access.



130
131
132
# File 'lib/ffc.rb', line 130

def last_access
  @last_access
end

#outputObject

Returns the value of attribute output.



130
131
132
# File 'lib/ffc.rb', line 130

def output
  @output
end

#output_bufferObject

Returns the value of attribute output_buffer.



130
131
132
# File 'lib/ffc.rb', line 130

def output_buffer
  @output_buffer
end

#output_pathObject

Returns the value of attribute output_path.



130
131
132
# File 'lib/ffc.rb', line 130

def output_path
  @output_path
end

#packageObject

Returns the value of attribute package.



130
131
132
# File 'lib/ffc.rb', line 130

def package
  @package
end

#pacmanObject

Returns the value of attribute pacman.



130
131
132
# File 'lib/ffc.rb', line 130

def pacman
  @pacman
end

#substituteObject

Returns the value of attribute substitute.



130
131
132
# File 'lib/ffc.rb', line 130

def substitute
  @substitute
end

#typeObject

Returns the value of attribute type.



130
131
132
# File 'lib/ffc.rb', line 130

def type
  @type
end

#warningObject

Returns the value of attribute warning.



130
131
132
# File 'lib/ffc.rb', line 130

def warning
  @warning
end

Instance Method Details

#brew!Object



175
176
177
178
179
# File 'lib/ffc.rb', line 175

def brew!
  status, stdout, stderr= systemu self.brew_command
  #status, stdout = Open3.capture2(self.brew_command)
  return status, stdout, stderr
end

#brew_commandObject



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ffc.rb', line 181

def brew_command
  if self.pacman
    return pacman + " " + package
  else
    if !@package_manager
      return "brew install " + package
    else
      return @package_manager + package
    end
  end
end

#cmd(inputs, output) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/ffc.rb', line 156

def cmd(inputs, output)
  cmd = self.command

  inputs.each{ |input| cmd.sub!("{input}", input)}
  cmd.sub!("{output}", output)
  return cmd
end

#generate_command(options, input, output) ⇒ Object



139
140
141
# File 'lib/ffc.rb', line 139

def generate_command(options, input, output)
  return [self.cmd, self.brew]
end

#generate_output_filename(input, option = :exchange) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ffc.rb', line 143

def generate_output_filename(input, option=:exchange)
  extensions = self.output
  case option
  when :exchange
    extensions = extensions.map{ |ext| Pathname(input).sub_ext("."+ext).to_s }
  when :prefix
    extensions = extensions.map{ |ext| input + "." + ext }
  #when :withtime
  #  extensions = extensions.map{ |ext| Pathname(input + "." + ext) }
  end
  extensions[0]
end

#run!(inputs, output, arguments = "") ⇒ Object



168
169
170
171
172
173
# File 'lib/ffc.rb', line 168

def run!(inputs, output, arguments="")
  raise "Error -- no input file" unless inputs.all?{ |t| Pathname(t).exist?}
  status, stdout, stderr = systemu self.cmd(inputs, output)

  return status, stdout, stderr
end

#to_sObject



164
165
166
# File 'lib/ffc.rb', line 164

def to_s
  return self.output.to_s + " " + self.cmd(@input_path, @output_path) + "  (" + self.package + ")"
end