Technology Agnostic Rubyist : Open Source Lights The Way

Tuesday, November 3, 2009

Fresh Cucumber

I've been putting together a little project using Rspec and Cucumber. It's a way of coding called Behaviour Driven Development and I'm loving it.

Here is Aslak Hellesøy's excellent backgrounder on Cucumber: BDD that talks to domain experts first and code second

.

Thursday, September 10, 2009

API Changes

I decided to read the eBay API Developer Newsletter today and was reminded why this API can be difficult to work with. The reason is not because it is complex or difficult to master. It is because the API is constantly evolving (good), and often the evolutionary changes cause previous working code to fail (not good).

After glancing past the Developer Success Stories I found this valuable nugget:
The eBay API team is considering changing the case of the appinfo tags found in various wsdls—specifically, changing from upper to lowercase on the first letter only. For example, CallName could become callName, RequiredInput could become requiredInput, and MaxLength could become maxLength.
In stark contrast, a quote from the home page of rubyonrails.org:
Ruby on Rails is an open source web framework that's optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favoring convention over configuration.
Can an API be designed in such a way as to make programmers Happy and Productive?

.

Friday, July 31, 2009

country_select and my country of origin inflector method

Making use of the string class add-on that I developed at the recent Goruco conference.

I've put together a simple little app and a domain where some of the code is available to anyone who can use it.

Please contact me if you are interested any part of this.

Saturday, May 30, 2009

Extending the String class

Feeling inspired after 2009 Gotham Ruby Conference, I finally wrote this.

class String

def nationalize
# retrieve a full xml list of countries and attributes
# if string matches the country name on the list return the
# nationality of the goods that originate from that country
# may not be the most efficient way, but it sure is extensible
@xml = open('http://originify.us/originify.us.xml')
country = REXML::Document.new(@xml)
country.elements.each('/countries/country') do |p|
return p.attributes['nationality'] if self.to_s == p.text.to_s
end
# returns self or superclass
self || super
end

end

It's an extension of the String class. I wanted to present the idea at the Reject Conference session but I'm glad I didn't. There were about 10 reject presentations and some were really good.

The way it works is simple. Just take any text string and use the nationalize method on it. For example, "France".nationalize => "French", "Switzerland".nationalize => "Swiss", "Australia".nationalize => "Australian".

This could be useful. Suppose you are a clothing retailer and have data for sweater in your database. The sweater has been assigned the attributes "Wool" and originating from "Australia" or "Switzerland" using a dropdown.

In describing the sweater on a web site, one might want to say that it is made of Swiss Wool.

This could be refactored.

Friday, April 3, 2009

Take away the RAD tools, TDD and BDD may be the best way to ensure good specifications before commencing a project.

Tuesday, March 31, 2009

Ruby on Rails Inflector for Nationality

I've given myself until midnight to complete the task I wrote about on November 25th.

The idea is for a Ruby Gem that provides a nationalize method for the String Class.

Any country code would be nationalized by simply typing something akin to "France".nationalize => "French" likewise "US".nationalize => "American"

As soon as I found a list country codes... I also realized I wouldn't have enough time to write the code and Gemify it. So I started hacking away at an Environment.rb file.

That got me something like this:
class String
# list of countries derived from http://www.internetworldstats.com/list2.htm#af
def nationalize
{
:Afghanistan => "Afghani",
:Africa => "African",
:Albania => "Albanian",
:Algeria => "Algerian",
:Andorra => "Andorra",
:Angola => "Angolan",
:Anguilla => "Anguilla",
:Antarctica => "Antarctic",
...
}[self.gsub(/_id$/, "").to_sym] || super
end


I decided this was getting a little cumbersome. Especially when I realized that any country with a space (char(32)) or other odd character in the name would need to be typecast as a :symbol in order for my code to work.

Options:
1) Devise out a work around, or
2) Plug away at the entire list of 230+ ISO country names and code for the exceptions

Of course one would prefer a more elegant and flexible solution. Have only two choices seemed awkward. So I did a little bit more research and found an XML list of countries.

This enabled another option:
3) Modify an XML country list to include nationality adjectives.

Now that I've modified the XML country list the data can be parsed, utlized, and published however one sees fit, in any computer program.

This is a flexible solution and completely language agnostic. I like it that way.

While I was thinking about this, I registered the domain name http://originfy.us. I will upload the XML file that I created to that domain.

Tuesday, January 13, 2009

No more email campaigns for me

Today I taught my client how to send email blasts. It was a BLAST.

Tweets

Contributors