Class: JLDrill::ListField

Inherits:
Field
  • Object
show all
Defined in:
lib/jldrill/model/items/ListField.rb

Constant Summary collapse

SEPARATOR_RE =
/[^\\],/

Constants inherited from Field

Field::ESCAPED_COMMA_RE, Field::ESCAPED_SLASH_RE, Field::QUOTE_RE, Field::RETURN_RE, Field::SLASH_RE

Instance Method Summary collapse

Methods inherited from Field

#assign, #assigned?, #processInput, #processOutput, #to_s

Constructor Details

#initialize(name, data) ⇒ ListField



11
12
13
14
# File 'lib/jldrill/model/items/ListField.rb', line 11

def initialize(name, data)
    super(name)
    @contents = data
end

Instance Method Details

#contentsObject



40
41
42
# File 'lib/jldrill/model/items/ListField.rb', line 40

def contents
    @contents
end

#copy(field) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/jldrill/model/items/ListField.rb', line 63

def copy(field)
    @contents = []
    if field.assigned?
        field.contents.each do |a|
            @contents.push(a)
        end
    else
        @contents = nil
    end
end

#eql?(array) ⇒ Boolean



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jldrill/model/items/ListField.rb', line 74

def eql?(array)
    if !assigned?
        return array.nil? || array.empty?
    end
       
    if array.nil? || array.empty?
        return false
    end

    if @contents.size != array.size
        return false
    end

    return @contents.eql?(array)
end

#fromString(string) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jldrill/model/items/ListField.rb', line 16

def fromString(string)
    if string.nil? || string.empty?
        @contents = nil
    else
        @contents = string.split(",")
        merge = false
        delete = []
        lastItem = 0
        0.upto(@contents.size - 1) do |i|
            if merge
                @contents[lastItem] += "," + @contents[i]
                delete.push(i)
            else
                lastItem = i
            end
            merge = @contents[i].end_with?("\\")
            @contents[i].strip!
        end
        delete.reverse.each do |i|
            @contents.delete_at(i)
        end
    end
end

#outputObject

I stupidly didn’t have spaces for my raw output previously so this means that I’ve got to duplicate this method here.



54
55
56
57
58
59
60
# File 'lib/jldrill/model/items/ListField.rb', line 54

def output
    if assigned?
        processOutput(@contents.join(", "))
    else
        ""
    end
end

#rawObject



44
45
46
47
48
49
50
# File 'lib/jldrill/model/items/ListField.rb', line 44

def raw
    if assigned?
        @contents.join(",")
    else
        ""
    end
end