Sha256: 6c7bb66b817449ff6ea48a54f47aa6d40de211ed8a838f466936db7478ee1390
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
require 'ostruct' module Uploadcare module Parser META_URL = / (?<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} # base uuid ~?(?<count>\d+)?) # optional count (?:\/-\/(?<operations>.*?))?\/?$ # optional operations /ix def self.parse string matched = META_URL.match(string) # just a simple hash - easy to pass next captured = Hash[ matched.names.zip( matched.captures ) ] # raise an error if no uuid was given in the sting raise "Invalid UUID or url was given" if captured["uuid"].nil? # operations sring to array of operations if captured["operations"] captured["operations"] = captured["operations"].split("/-/") else captured["operations"] = [] end # if count was given - it is a group if captured["count"] obj = Group.new captured else obj = File.new captured end end class File < OpenStruct end class Group < OpenStruct end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
uploadcare-ruby-1.0.1.rc2 | lib/uploadcare/api/parser.rb |
uploadcare-ruby-1.0.1.rc1 | lib/uploadcare/api/parser.rb |