[ANN] LXL (Like Excel) 0.3.0

K

Kevin Howe

LXL (Like Excel) is a mini-language that mimics Microsoft Excel formulas.
Easily extended with new constants and functions.

Version 0.3.0 supports the following features:

=Namespaces [NEW]

Extending the language is now as easy as defining new constants
and methods on an LXL::Namespace class, for immediate use in formulas.

class MyLXLNamespace < LXL::Namespace
NAME = 'John Doe'
def upper(text) text.to_s.upcase end
end

class MyLXL < LXL::parser
def self.namespace_class() MyLXLNamespace end
end

MyLXL.eval('=UPPER(NAME)')
# => JOHN DOE

=Ranges [NEW]

B3:D5 => LXL::Range.new("B3","D5")

LXL::Range is a subclass of Range which overrides
the #each method to return Excel-style ranges.

# Ruby Range
Range.new("B3", "D5").collect
# => ["B3", "B4", "B5", "B6", "B7", "B8", "B9",
"C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9",
"D0", "D1", "D2", "D3", "D4", "D5"]

# LXL Range
LXL::Range.new("B3", "D5").collect
# => ["B3", "B4", "B5", "C3", "C4", "C5", "D3", "D4", "D5"]

=Percentages [NEW]

25% => .25

=Deferred function calls [NEW]

Snapshots the symbol/arguments of a function call for later use.

class MyNamespace < LXL::Namespace
register_deferred :foo
end
LXL.new(MyNamespace.new).eval('=FOO(1, "two", 3)').inspect
# => <LXL::Deferred @args=[1, "two", 3] @symbol=:foo>

=Symbol registration

Register uppercase constants of the same name and value.

class MyNamespace < LXL::Namespace
register_symbols :foo, :bar
end
LXL.new(MyNamespace.new).eval('=LIST(FOO, BAR)').inspect
# => [:FOO, :BAR]

=Operators

a + b # Add
a - b # Subtract
a * b # Multiply
a / b # Divide
a = b # Equal to
a <> b # Not equal to
a < b # Less than
a > b # Greater than
a <= b # Less than or equal to
a >= b # Greater than or equal to

a & b # String concentation [NEW]
n ^ n # Exponential [NEW]

=Constants

TRUE # true
FALSE # false
NULL # nil

=Functions

Logical Functions

AND (a,b)
OR (a,b)
IF (cond,true,false)

Date/Time Functions

TODAY () # current date value
NOW () # current date/time value
DATE (y,m,d) # date value
TIME (h,m,s) # time value
DATETIME (value) # convert a date/time string into a date/time value

List Functions

LIST (a,b,..) # Variable length list
IN (find,list) # True if find value is in the given list (works on
strings too)

=Notes

* The number zero is interpereted as FALSE
* Return multiple results in an array by separating formulas with a
semi-colon (;)
* Constant and Function names are case-insensitive
* Values prefixed with = are formulas, anything else is assumed to be text:

LXL.eval("5+5") # => '5+5'
LXL.eval("=5+5") # => 10

Regards,
Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top