use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlAttr method value_set.
@JRubyMethod(name = { "value=", "content=" })
public IRubyObject value_set(ThreadContext context, IRubyObject content) {
Attr attr = (Attr) node;
attr.setValue(rubyStringToString(XmlNode.encode_special_chars(context, content)));
setContent(content);
return content;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method key_p.
/**
* Test if this node has an attribute named <code>rbkey</code>.
* Overridden in XmlElement.
*/
@JRubyMethod(name = { "key?", "has_attribute?" })
public IRubyObject key_p(ThreadContext context, IRubyObject rbkey) {
if (node instanceof Element) {
String key = rubyStringToString(rbkey);
Element element = (Element) node;
return context.getRuntime().newBoolean(element.hasAttribute(key));
} else {
return context.getRuntime().getNil();
}
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method namespace_definitions.
/**
* Return an array of XmlNamespace nodes based on the attributes
* of this node.
*/
@JRubyMethod
public IRubyObject namespace_definitions(ThreadContext context) {
// don't use namespace_definitions cache anymore since
// namespaces might be deleted. Reflecting the result of
// namesapce removals is complicated, so the cache might not be
// updated.
Ruby ruby = context.getRuntime();
RubyArray namespace_definitions = ruby.newArray();
if (doc == null)
return namespace_definitions;
if (doc instanceof HtmlDocument)
return namespace_definitions;
List<XmlNamespace> namespaces = ((XmlDocument) doc).getNamespaceCache().get(node);
for (XmlNamespace namespace : namespaces) {
namespace_definitions.append(namespace);
}
return namespace_definitions;
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class MathToolModule method norm_strict.
/**
* Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
* of the range are clamped to 0 and 1,
*
* @param context ThreadContext
* @param recv IRubyObject
* @param args array of args must be be numeric
* @return mapped value RubyFloat
*/
@JRubyMethod(name = "norm_strict", rest = true, module = true)
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby ruby = context.runtime;
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
double max = Math.max(start, stop);
double min = Math.min(start, stop);
if (value < min) {
return mapMt(context, min, start, stop, 0, 1.0);
}
if (value > max) {
return mapMt(context, max, start, stop, 0, 1.0);
}
return mapMt(context, value, start, stop, 0, 1.0);
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method from_angle.
/**
* Example of a regular ruby class method Use Math rather than RadLut
* here!!!
*
* @param context ThreadContext
* @param klazz IRubyObject
* @param scalar input angle in radians
* @return new Vec2 object (ruby)
*/
@JRubyMethod(name = "from_angle", meta = true)
public static IRubyObject from_angle(ThreadContext context, IRubyObject klazz, IRubyObject scalar) {
Ruby runtime = context.runtime;
double angle = (scalar instanceof RubyFloat) ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
return Vec2.rbNew(context, klazz, new IRubyObject[] { runtime.newFloat(Math.cos(angle)), runtime.newFloat(Math.sin(angle)) });
}
Aggregations