I have an input, which can have different structure. I would like to test few patterns and get corresponding matching parts in each case without repeating the regular expressions. For example:
a = "hello123"
case a
when /^([0-9]+)([a-z]+)$/
# how to get matching values?
when /^([a-z]+)([0-9]+)$/
# how to get matching values?
else
en...
I have this:
h = { 1 => { 1 => {:a => "x", :b => "y", :c => "z"},
2 => {:a => "xx", :b => "yy", :c => "zz"}
},
2 => { 1 => {:a => "p", :b => "q", :c => "r"},
2 => {:a => "pp", :b => "qq", :c => "rr"}
}
}
I want to get this:
result = { 1 => { 1 => {:a => "x"},
...
Is it possible to associate a stylesheet with with Nokogiri, to create this structure?
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://www.my-site.com/sitemap.xsl"?>
<root>
...
</root>
...
Hi...
I've been trying to setup autotest with rails 3 beta4 but I getting a "-bash: autotest: command not found" -- any ideas?
I installed it by putting the gem in my gemfile and then doing a bundle install..
...
I've got a script that searches through a logfile for a specific trigger, and then pulls out the line when it's found. For example, this is a line I'm looking for:
7/2/10 9:24:12 AM puppetmasterd[63092] Could not resolve 10.13.1.190: no name for 10.13.1.190
It saves this line into a variable "line", but I'd like to be able to extrac...
I have a Rakefile that defines the spec task as
task :spec => [:check_dependencies, :load_backends]
And then runs the actual rspec tests. During the load_backends task, it loads a class called Story, but in the first spec test, defined?(Story) returns false.
I'm assuming that it is intended behavior of Rake to start with a fresh env...
I'm running ruby on Mac OSX 10.6.4, using Ruby 1.8 and activerecord 2.3.8. I'm running the following code inside of NetBeans 6.9 but I'm using the ruby interpreter from 10.6
I have the following code:
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection
(
:adapter=> "mysql",
:host => "localhost",...
Hi all,
I'm trying to build a Sanitize transformer that accepts potentially malformed HTML input with elements outside of any tags at all, such as in this example:
out of a tag<p>in a tag</p>out again!
I want to have the transformer wrap any non-tagged elements in <p> tags so that the above transforms into:
<p>out of a tag</p><p>in ...
I have a question about best practices for Ruby variable scope using class_eval.
In the below code snippet, in the class_eval block, the local variables first and second are undefined.
def parent_method(opts={})
first = opts[:percent]
second = (10 * first).to_i
SecondClass.class_eval do
def second_method; return {:...
I'm using a rake script to tag the AssemblyInfo.cs files in my .NET projects, but there's a phantom carriage return (or newline, etc.) being introduced that's breaking the compilation. The method that gets the version number is:
def get_version()
version = ''
IO.popen("#{SVNVERSION_APPLICATION} #{build_info.root_dir}") do |output|
...
Is there any way to do something like this?
a = Struct.new(:c).new(1)
b = Struct.new(:c).new(2)
a.send(:c)
=> 1
b.send(:c)
=> 2
a.send(:c) = b.send(:c)
The last line result in error:
syntax error, unexpected '=', expecting $end
a.send(:c) = b.send(:c)
^
...
I'm using some ruby code wrapped in a begin - rescue block but somehow it manages to still crash.
the block of code looks like this:
# Retrieve messages from server
def get_messages
@connection.select('INBOX')
@connection.uid_search(['ALL']).each do |uid|
msg = @connection.uid_fetch(uid,'RFC822').first.attr['RFC822']
begin...
In a ruby string, how can I insert a space every X number of characters?
As an example, I'd like to insert a space every 8 characters of a given string.
...
Am using RingyDingy.
Have altered call to Rinda::RingFinger.new to Rinda::RingFinger.new('localhost') in ring_server.rb and in ringy_dingy.rb, but still get, intermittently, attachments to like named services on my compatriots (in the same lan segment) which causes things to disappear trying to run on their machine (or on mine from the...
In this question, the asker requests a solution that would insert a space every x number of characters. The answers both involve using a regular expression. How might you achieve this without a regex?
Here's what I came up with, but it's a bit of a mouthful. Any more concise solutions?
string = "12345678123456781234567812345678"
new_st...
I'm still fairly new in using Watir for automation testing and I've hit another possibly insanely easy problem that I need to reach out to the community for a little bump in the right direction.
I'm trying to use logger in Watir, which I can get to work fine if I keep everything within methods. If I don't have a method defined, for ins...
Hello,
I have a .gz file that contains an XML document. I was wondering anyone knew how to use Zlib properly. So far, I have the following code:
require 'zlib'
Zlib::GzipReader.open('PRIDE_Exp_Complete_Ac_1015.xml.gz') { |gz|
g = File.new("PRIDE_Exp_Complete_Ac_1015.xml", "w")
g.write(gz)
g.close()
}
But this creates ...
Hey all,
I'm using delayed_job for a priority queue. I was wondering how do i define what a failed job is?
Thanks.
...
Hi there,
I created a Shoes application that reads some data from a YAML file on APP_PATH/data folder.
The application works so well that I decided to package and send to a friend.
I created an Windows executable with Shoes inside. When I run the executable, the relative path ./data does not point to the data folder inside the executa...
We want to grant automatic access to premium content (that is ordinarily password protected) to student client requests coming via their university's proxy server.
Any ideas on how to go about this for a ruby on rails app?
...