diff --git a/README.md b/README.md index db244fe..0e35955 100644 --- a/README.md +++ b/README.md @@ -267,8 +267,6 @@ MQ::Query.list.map { contains("important") } .rtrim # rtrim() .downcase # downcase() .upcase # upcase() -.ascii_downcase # ascii_downcase() -.ascii_upcase # ascii_upcase() .len # len() .utf8bytelen # utf8bytelen() .explode # explode() — string to codepoints @@ -290,12 +288,12 @@ MQ::Query.list.map { contains("important") } #### Collection Operations ```ruby -.length # length +.length # len() .len # len() -.add # add +.add("x") # add("x") .first # first .last # last -.empty # empty +.empty # is_empty() .reverse # reverse .sort # sort .compact # compact — remove nils @@ -306,8 +304,8 @@ MQ::Query.list.map { contains("important") } .entries # entries .children # .children .join(", ") # join(", ") -.nth(2) # nth(2) -.limit(5) # limit(5) +.nth(2) # get(2) +.limit(5) # take(5) .range(3) # range(3) .del("key") # del("key") .insert(0, "val") # insert(0, "val") diff --git a/lib/mq/query.rb b/lib/mq/query.rb index 1e6eb15..0dc8db2 100644 --- a/lib/mq/query.rb +++ b/lib/mq/query.rb @@ -70,13 +70,17 @@ def to_array = pipe_with("to_array()") def to_bytes = pipe_with("to_bytes()") def to_markdown_string = pipe_with("to_markdown_string()") - def length = pipe_with("length") + def length = pipe_with("len()") def len = pipe_with("len()") def utf8bytelen = pipe_with("utf8bytelen()") - def add = pipe_with("add") + + def add(other) + pipe_with("add(#{other.inspect})") + end + def first = pipe_with("first") def last = pipe_with("last") - def empty = pipe_with("empty") + def empty = pipe_with("is_empty()") def reverse = pipe_with("reverse") def sort = pipe_with("sort") def compact = pipe_with("compact") @@ -96,11 +100,11 @@ def join(separator) end def nth(n) - pipe_with("nth(#{n})") + pipe_with("get(#{n})") end def limit(n) - pipe_with("limit(#{n})") + pipe_with("take(#{n})") end def range(n) @@ -136,8 +140,6 @@ def ltrim = pipe_with("ltrim()") def rtrim = pipe_with("rtrim()") def downcase = pipe_with("downcase()") def upcase = pipe_with("upcase()") - def ascii_downcase = pipe_with("ascii_downcase()") - def ascii_upcase = pipe_with("ascii_upcase()") def explode = pipe_with("explode()") def implode = pipe_with("implode()") def url_encode = pipe_with("url_encode()") @@ -538,12 +540,11 @@ def is_nan = Filter.new("is_nan()") def type = Filter.new("type") # String transforms usable in filter context - def length = Filter.new("length") - def ascii_downcase = Filter.new("ascii_downcase()") - def ascii_upcase = Filter.new("ascii_upcase()") + def length = Filter.new("len()") def trim = Filter.new("trim()") - def empty = Filter.new("empty") - def add = Filter.new("add") + def empty = Filter.new("is_empty()") + + def add(other) = Filter.new("add(#{other.inspect})") # Negate a filter expression with not(). # Use +negate+ instead of +not+ since +not+ is a Ruby keyword. diff --git a/spec/mq_spec.rb b/spec/mq_spec.rb index 10d09bb..6935a7d 100644 --- a/spec/mq_spec.rb +++ b/spec/mq_spec.rb @@ -380,8 +380,6 @@ it "chains rtrim" do expect(MQ::Query.text.rtrim.to_query).to eq(".text | rtrim()") end it "chains downcase" do expect(MQ::Query.text.downcase.to_query).to eq(".text | downcase()") end it "chains upcase" do expect(MQ::Query.text.upcase.to_query).to eq(".text | upcase()") end - it "chains ascii_downcase" do expect(MQ::Query.text.ascii_downcase.to_query).to eq(".text | ascii_downcase()") end - it "chains ascii_upcase" do expect(MQ::Query.text.ascii_upcase.to_query).to eq(".text | ascii_upcase()") end it "chains explode" do expect(MQ::Query.text.explode.to_query).to eq(".text | explode()") end it "chains implode" do expect(MQ::Query.text.implode.to_query).to eq(".text | implode()") end it "chains url_encode" do expect(MQ::Query.text.url_encode.to_query).to eq(".text | url_encode()") end @@ -427,11 +425,11 @@ end describe "collection/array methods" do - it "chains length" do expect(MQ::Query.list.length.to_query).to eq(".[] | length") end - it "chains add" do expect(MQ::Query.list.add.to_query).to eq(".[] | add") end + it "chains length" do expect(MQ::Query.list.length.to_query).to eq(".[] | len()") end + it "chains add" do expect(MQ::Query.list.add("x").to_query).to eq('.[] | add("x")') end it "chains first" do expect(MQ::Query.list.first.to_query).to eq(".[] | first") end it "chains last" do expect(MQ::Query.list.last.to_query).to eq(".[] | last") end - it "chains empty" do expect(MQ::Query.list.empty.to_query).to eq(".[] | empty") end + it "chains empty" do expect(MQ::Query.list.empty.to_query).to eq(".[] | is_empty()") end it "chains reverse" do expect(MQ::Query.list.reverse.to_query).to eq(".[] | reverse") end it "chains sort" do expect(MQ::Query.list.sort.to_query).to eq(".[] | sort") end it "chains compact" do expect(MQ::Query.list.compact.to_query).to eq(".[] | compact") end @@ -442,8 +440,8 @@ it "chains entries" do expect(MQ::Query.list.entries.to_query).to eq(".[] | entries") end it "chains children" do expect(MQ::Query.list.children.to_query).to eq(".[] | .children") end - it "chains nth" do expect(MQ::Query.h2.nth(2).to_query).to eq(".h2 | nth(2)") end - it "chains limit" do expect(MQ::Query.h2.limit(5).to_query).to eq(".h2 | limit(5)") end + it "chains nth" do expect(MQ::Query.h2.nth(2).to_query).to eq(".h2 | get(2)") end + it "chains limit" do expect(MQ::Query.h2.limit(5).to_query).to eq(".h2 | take(5)") end it "chains range" do expect(MQ::Query.h2.range(3).to_query).to eq(".h2 | range(3)") end it "chains join" do