Java Code Examples for org.jruby.runtime.builtin.IRubyObject#asJavaString()
The following examples show how to use
org.jruby.runtime.builtin.IRubyObject#asJavaString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyntaxHighlighterProxy.java From asciidoctorj with Apache License 2.0 | 6 votes |
@JRubyMethod(name = "highlight", required = 4) public IRubyObject highlight(ThreadContext context, IRubyObject[] args) { Highlighter highlighter = (Highlighter) delegate; IRubyObject blockRuby = args[0]; Block block = (Block) NodeConverter.createASTNode(blockRuby); IRubyObject sourceRuby = args[1]; String source = sourceRuby.asJavaString(); IRubyObject langRuby = args[2]; String lang = langRuby.asJavaString(); RubyHash optionsRuby = (RubyHash) args[3]; Map<String, Object> options = new RubyHashMapDecorator(optionsRuby); HighlightResult result = highlighter.highlight(block, source, lang, options); if (result.getLineOffset() != null) { return getRuntime().newArray(getRuntime().newString(result.getHighlightedSource()), getRuntime().newFixnum(result.getLineOffset())); } else { return getRuntime().newString(result.getHighlightedSource()); } }
Example 2
Source File: JavaLogger.java From asciidoctorj with Apache License 2.0 | 5 votes |
private String formatMessage(final IRubyObject msg) { if (getRuntime().getString().equals(msg.getType())) { return msg.asJavaString(); } else if (getRuntime().getHash().equals(msg.getType())) { final RubyHash hash = (RubyHash) msg; return Objects.toString(hash.get(getRuntime().newSymbol(LOG_PROPERTY_TEXT))); } throw new IllegalArgumentException(Objects.toString(msg)); }
Example 3
Source File: RubyObjectWrapper.java From asciidoctorj with Apache License 2.0 | 5 votes |
public String getString(String propertyName, Object... args) { IRubyObject result = getRubyProperty(propertyName, args); if (result instanceof RubyNil) { return null; } else if (result instanceof RubySymbol) { return result.asJavaString(); } else { return result.asJavaString(); } }
Example 4
Source File: RubyObjectWrapper.java From asciidoctorj with Apache License 2.0 | 5 votes |
public String getSymbol(String propertyName, Object... args) { IRubyObject result = getRubyProperty(propertyName, args); if (result instanceof RubyNil) { return null; } return result.asJavaString(); }
Example 5
Source File: SyntaxHighlighterProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
@JRubyMethod(name = "write_stylesheet", required = 2) public IRubyObject writeStylesheet(ThreadContext context, IRubyObject document, IRubyObject to_dir) { StylesheetWriter writer = (StylesheetWriter) delegate; Document doc = (Document) NodeConverter.createASTNode(document); File toDir = new File(to_dir.asJavaString()); writer.writeStylesheet(doc, toDir); return getRuntime().getNil(); }
Example 6
Source File: SyntaxHighlighterProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
@JRubyMethod(name = "format", required = 3) public IRubyObject format(ThreadContext context, IRubyObject blockRuby, IRubyObject langRuby, IRubyObject optionsRuby) { Formatter formatter = (Formatter) delegate; Block block = (Block) NodeConverter.createASTNode(blockRuby); String lang = langRuby.asJavaString(); Map<String, Object> options = new RubyHashMapDecorator((RubyHash) optionsRuby); String result = formatter.format(block, lang, options); return getRuntime().newString(result); }