Class: S3Direct::StringInterpolator
- Inherits:
-
Object
- Object
- S3Direct::StringInterpolator
- Defined in:
- lib/s3direct/string_interpolator.rb
Constant Summary collapse
- DELIM =
"/"
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #compile_parts ⇒ Object
-
#initialize(context, pattern) ⇒ StringInterpolator
constructor
A new instance of StringInterpolator.
- #to_s ⇒ Object
Constructor Details
#initialize(context, pattern) ⇒ StringInterpolator
Returns a new instance of StringInterpolator.
7 8 9 10 |
# File 'lib/s3direct/string_interpolator.rb', line 7 def initialize(context, pattern) @pattern = pattern @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/s3direct/string_interpolator.rb', line 5 def context @context end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
5 6 7 |
# File 'lib/s3direct/string_interpolator.rb', line 5 def pattern @pattern end |
Instance Method Details
#compile_parts ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/s3direct/string_interpolator.rb', line 16 def compile_parts pattern.split(DELIM).collect do |part| if part[0] == ':' meth = part[1, part.length - 1] result = context.public_send meth if result.blank? raise ":#{meth} for path '#{pattern}' was blank in #{context.inspect}" end result.to_s.underscore else part end end end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/s3direct/string_interpolator.rb', line 12 def to_s compile_parts.join(DELIM) end |