Sha256: 7d1f885023d50f47585a5d70c9293cd84b36092de76f64fff41b84f3bfdda275
Contents?: true
Size: 801 Bytes
Versions: 5
Compression:
Stored size: 801 Bytes
Contents
module Parsable class Parser REGEX = /\{{2}(\w*\.?\S[^\{\{]*)\}{2}/ attr_accessor :original_string, :strings def initialize args={} @original_string = args.fetch(:string).to_s end def parse strings.map do |string| object, attribute = capture(string) Parsable::ParsedItem.new(\ :original => string, :object => object, :attribute => attribute ) end end private def capture string [capture_object(string), capture_attribute(string)] end def strings @strings ||= original_string.to_s.scan(REGEX).flatten end def capture_object string string[/(\w*)\.?\S*/, 1] end def capture_attribute string string[/\w*\.?(\S*)/, 1] end end end
Version data entries
5 entries across 5 versions & 1 rubygems