Class: Cranium::DSL::SourceDefinition

Inherits:
Object
  • Object
show all
Extended by:
AttributeDSL
Defined in:
lib/cranium/dsl/source_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeDSL

define_array_attribute, define_attribute, define_boolean_attribute

Constructor Details

#initialize(name) ⇒ SourceDefinition

Returns a new instance of SourceDefinition.



19
20
21
22
23
24
25
26
27
# File 'lib/cranium/dsl/source_definition.rb', line 19

def initialize(name)
  @name = name
  @file = default_file_name
  @fields = {}
  @delimiter = ","
  @escape = '"'
  @quote = '"'
  @encoding = "UTF-8"
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/cranium/dsl/source_definition.rb', line 9

def fields
  @fields
end

#filesObject (readonly)

Returns the value of attribute files.



8
9
10
# File 'lib/cranium/dsl/source_definition.rb', line 8

def files
  @files
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cranium/dsl/source_definition.rb', line 7

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/cranium/dsl/source_definition.rb', line 49

def ==(other)
  name == other.name and
    file == other.file and
    delimiter == other.delimiter and
    escape == other.escape and
    quote == other.quote and
    encoding == other.encoding and
    fields == other.fields
end

#field(name, type) ⇒ Object



37
38
39
# File 'lib/cranium/dsl/source_definition.rb', line 37

def field(name, type)
  @fields[name] = type
end

#file_name_overriden?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cranium/dsl/source_definition.rb', line 43

def file_name_overriden?
  @file != default_file_name
end

#resolve_filesObject



31
32
33
# File 'lib/cranium/dsl/source_definition.rb', line 31

def resolve_files
  @files = Dir[File.join Cranium.configuration.upload_path, @file].map { |file| File.basename file }.sort
end