Class: JLDrill::Field
- Inherits:
-
Object
- Object
- JLDrill::Field
- Defined in:
- lib/jldrill/model/items/Field.rb
Direct Known Subclasses
Constant Summary collapse
- QUOTE_RE =
/["]/
- RETURN_RE =
/[\n]/
- SLASH_RE =
/[\/]/
- ESCAPED_COMMA_RE =
Regexp.new("\\,", nil)
- ESCAPED_SLASH_RE =
Regexp.new("\\/", nil)
Instance Method Summary collapse
- #assign(string) ⇒ Object
- #assigned? ⇒ Boolean
-
#initialize(name) ⇒ Field
constructor
A new instance of Field.
- #output ⇒ Object
- #processInput(text) ⇒ Object
- #processOutput(text) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Field
Returns a new instance of Field.
21 22 23 |
# File 'lib/jldrill/model/items/Field.rb', line 21 def initialize(name) @name = name end |
Instance Method Details
#assign(string) ⇒ Object
42 43 44 45 |
# File 'lib/jldrill/model/items/Field.rb', line 42 def assign(string) string = processInput(string) fromString(string) end |
#assigned? ⇒ Boolean
47 48 49 |
# File 'lib/jldrill/model/items/Field.rb', line 47 def assigned? !contents().nil? && !contents.empty? end |
#output ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/jldrill/model/items/Field.rb', line 51 def output if assigned? processOutput(raw()) else nil end end |
#processInput(text) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/jldrill/model/items/Field.rb', line 25 def processInput(text) if text.nil? || text.empty? return nil end text = text.gsub(RETURN_RE, "\\n") text end |
#processOutput(text) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/jldrill/model/items/Field.rb', line 33 def processOutput(text) if text.nil? return nil end text = text.gsub(ESCAPED_COMMA_RE, ",") text = text.gsub(ESCAPED_SLASH_RE, "/") eval("\"#{text.gsub(QUOTE_RE, "\\\"")}\"") end |
#to_s ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/jldrill/model/items/Field.rb', line 59 def to_s if assigned? "/#{@name}: " + raw() else "" end end |