# Monster method (too hard for my skill level)

**URL:** <https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893>\
**Category:** Rails\
**Created:** [November 1, 2007, 4:01am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893 "2007-11-01T04:01:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 1, 2007, 4:01am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/1 "2007-11-01T04:01:34Z")

</div>

I need to write a method for calculating the fee for medical  
procedures with respect to area. I have all the tables and data but  
its hard to give that here. Can someone take a look at this ‘stub’  
method and help me out?

def calculate\_fee

# strip out the first 3 numbers of the user entered zip code

# use those 3 numbers to identify row in [zipcodes table] (between

upper and lower zip code columns))

# identify ‘RVS ID’ from that row

# identify the ‘geographic zip area’ from that row

# query on user entered procedure description using [procedures table]

to identify ‘procedure code’

# use previously obtained ‘RVS ID’ and ‘Procedure code’ to get

‘Relative value’ from [relative values table]

# use previously obtained ‘geographic zip area’ and ‘procedure code’

to identify ‘percentile’ from

# [geographic factors table]

# use formula (Percentile / 1000) x (Relative Value / 100) to

calculate fee

end

anything in quotes is a column from one of my tables and anything in  
brackets is a table. I know this is a tough scenario without seeing  
the tables but any help would be a start and I can answer any  
questions if you are trying to help.

THANK YOU

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 1, 2007, 4:42am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/2 "2007-11-01T04:42:29Z")

</div>

Without any idea of your schema I’m completely stabbing in the dark  
here. but…

def calculate\_fee

# strip out the first 3 numbers of the user entered zip code

zip = params[:id].first(3)

# use those 3 numbers to identify row in [zipcodes table] (between

upper and lower zip code columns))  
@zip = ZipCode.find(zip)

# identify ‘RVS ID’ from that row ## You don’t need to do this, you

can get it through the object @zip.rvs\_id (or whatever the column is  
really called)

# identify the ‘geographic zip area’ from that row ## Same as

above.

# query on user entered procedure description using [procedures

table] to identify ‘procedure code’  
@procedure = Procedure.find\_by\_procedure\_code(params[:procedure]  
[:code]) # This param depends on your form your posting in from?

# use previously obtained ‘RVS ID’ and ‘Procedure code’ to get

‘Relative value’ from [relative values table]  
@relative\_value = RelativeValue.find(:first, :conditions =\> [‘rvs\_id  
= ? AND procedure\_code = ?’, @zip.rvs\_id, @procedure.procedure\_code])

# But what does this return I don’t what your objects return mate.

# use previously obtained ‘geographic zip area’ and ‘procedure code’

to identify ‘percentile’ from [geographic factors table]  
@percentile = GeographicFactor.find(:first, :conditions =\>  
[‘geographic\_zip\_area = ? AND procedure\_code = ?’,  
@zip.geographic\_zip\_area, @procedure.procedure\_code])  
use formula (Percentile / 1000) x (Relative Value / 100) to  
calculate fee  
return (@percentile.(some attribute) / 1000) \* (@relative\_value.  
(some attribute) / 1000)  
end

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 1, 2007, 5:32am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/3 "2007-11-01T05:32:46Z")

</div>

The code is there, to get the column, just use the accessor for that  
column like this:

@zip.rvs\_id

of course, that assumes that is the column name, if it is named  
something else, just sub it for rvs\_id.

-Bill

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 1, 2007, 5:25am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/4 "2007-11-01T05:25:44Z")

</div>

how do you do this…

# identify ‘RVS ID’ from that row ## You don’t need to do this, you

can get it through the object @zip.rvs\_id (or whatever the column is  
really called)

I understand that each row is an object, so it makes sense - just not  
sure how to execute

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 3:43am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/5 "2007-11-06T03:43:15Z")

</div>

this confuses me…

@zip = ZipCode.find(zip)

where @zip is the first 3 digits of a zipcode  
the table is zipcodes the model zipcode

so i understand @zip = Zipcode.find(zip) is attempting to look for zip  
in the zipcodes table via the model zipcode

however i need to compare my 3 digit zip (@zip) againt two columns in  
the table  
column 1 - zipstart  
column 2 - endzip

i need to find the row that my @zip falls inside the values of those  
two columns, so i believe this line of code is too simple

example might be @zip = 034  
startzip = 032 and endzip =037 in the table  
i need to identify that row

can anyone help?

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 4:22am UTC](https://www.ruby-forum.com/t/monster-method-too-hard-for-my-skill-level/118893/6 "2007-11-06T04:22:59Z")

</div>

@zip = ZipCode.find(:all, :conditions =\> ["startzip \<= ? AND endzip

> = ?", zip, zip])
