class Albacore::Asmver::Engine

Constants

NL

Public Instance Methods

build_attribute(attr_name, attr_data) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 3
def build_attribute attr_name, attr_data
  attribute = "#{@start_token}assembly: #{format_attribute_name attr_name}("

  unless attr_data.nil?
    if attr_data.is_a? Hash
      # Only named parameters
      attribute << build_named_parameters(attr_data)
    elsif attr_data.is_a? Array
      if attr_data.last.is_a? Hash
        # Positional and named parameters
        attribute << build_positional_parameters(attr_data.slice(0, attr_data.length - 1))
        attribute << ", "
        attribute << build_named_parameters(attr_data.last)
      else
        # Only positional parameters
        attribute << build_positional_parameters(attr_data)
      end
    else
      # Single positional parameter
      attribute << "#{format_value attr_data}"
    end
  end

  attribute << ")#{@end_token}"
end
build_comment(string_data) click to toggle source

builds a comment, as a single line if it's a single line otherwise builds a multiline comment

# File lib/albacore/task_types/asmver/engine.rb, line 54
def build_comment string_data
  if is_multiline string_data
    build_multiline_comment string_data
  else
    build_singleline_comment string_data
  end
end
build_named_parameters(data) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 29
def build_named_parameters data
  params = []
  data.each_pair do |k, v|
    params << "#{k.to_s} #{@assignment} #{format_value v}"
  end
  params.join ", "
end
build_namespace(namespace, writer, &in_namespace) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 45
def build_namespace namespace, writer, &in_namespace
  raise ArgumentError, "missing block to #build_namespace on #{self.inspect}" unless block_given?
  writer << namespace_start(namespace)
  in_namespace.call namespace
  writer << namespace_end
end
build_positional_parameters(data) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 37
def build_positional_parameters data
  data.flatten.map{ |a| format_value a }.join(", ")
end
build_using_statement(namespace) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 41
def build_using_statement namespace
  "#{@using} #{namespace}#{@statement_terminator}"
end

Protected Instance Methods

build_multiline_comment(string_data) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 116
def build_multiline_comment string_data
  comment_multiline_start + "\n" +
    string_data.split(NL).map{ |s| " " + s }.join("\n") + "\n" +
    comment_multiline_end
end
build_singleline_comment(string_data) click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 122
def build_singleline_comment string_data
  %Q|#{comment_singleline_token} #{string_data}|
end
comment_multiline_end() click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 112
def comment_multiline_end
  '*/'
end
comment_multiline_start() click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 108
def comment_multiline_start
  '/*'
end
comment_singleline_token() click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 104
def comment_singleline_token
  '//'
end
format_attribute_name(name) click to toggle source

formats what might be a snake_case attribute, in CamelCase.

# File lib/albacore/task_types/asmver/engine.rb, line 69
def format_attribute_name name
  return name if name !~ /_/ && name =~ /[A-Z]+.*/
  name.split('_').map{ |e| e.capitalize }.join 
end
format_value(v) click to toggle source

formats a value according to its type to make it more rubyesque

# File lib/albacore/task_types/asmver/engine.rb, line 75
def format_value v
  case v
  when String
    v.inspect
  when TrueClass
    'true'
  when FalseClass
    'false'
  else
    v.to_s
  end
end
is_multiline(str) click to toggle source

For comments

# File lib/albacore/task_types/asmver/engine.rb, line 100
def is_multiline str
  str =~ NL
end
namespace_end() click to toggle source
# File lib/albacore/task_types/asmver/engine.rb, line 94
def namespace_end
  "}" 
end
namespace_start(namespace) click to toggle source

For namespaces

# File lib/albacore/task_types/asmver/engine.rb, line 90
def namespace_start namespace
  "namespace #{namespace} {"
end