I believe the order of gun colors is: White, Green, Blue, Purple, Magenta, Orange, and I get that those basically increase in quality from left to right. What I'm interested in is what exactly improves as you move up through the color grades. Does each added grade add more minimum affixes, similar to Diablo? Are damage minimums adjusted? Do some affixes only occur in certain quality grades? etc...
Weapon grade is a measure of the rarity of all combined parts, unless radical departures have been made from Borderlands 1's rarity system. From my in-game experience the general system is the same, though minor tweaks to how rarity is counted may well have occured.
The way it works is guns are made of parts. The unique stats of each gun at the same level are due to their parts. Parts have different stats; rarer parts have a higher rarity and generally better stats or special effects.
The total rarity of all parts determines the color. Guns with crap, common parts are White. Guns with good, non-unique parts are green or blue, or sometimes even Purple. Legendary parts, the parts that turn a good gun into a recognizable, named gun, have extremely high rarity values which force them into the Orange category. Unique parts (like named, unique quest rewards) always push a gun into at least blue rarity.
Rarer parts are stronger in general, but may have other weaknesses. You should always compare the actual stats of the items. (Note: Level requirement always plays a role in how powerful an item is and, as always, actually give the new gun a try before ditching the old one. So a purple weapon for level 8 may not be as good as a green weapon for level 11.) You can also generally disregard White weapons after a certain level as they have no particularly special parts.
Also Class Mods (COMs) have an explicit rarity function; white COMs boost stats but not skills, green COMs boost one skill, blue COMs boost two, and Purple COMs boost three. I don't believe there are legendary COMs (there weren't in Borderlands 1). There aren't identifiable "parts" for COMs (there are for Shields and Grenades however), but you can tell all you need to know from their stats alone.
The Borderlands 2 loot system does take a large step away from that of Borderlands 1.
First, rarity is not determined by the sum of the parts like in the first game. The only parts that are rarity specific are barrels. This includes legendary, unique, and e-tech loot.
While E-tech is purple, unique is blue, legendary is its own specific rarity.... sort of.
To elaborate a bit more, unlike the first game, guns do not spawn with random bodies (or mags, those have been integrated into the body) or materials. Both are locked to a specific rarity. For ease of explanation, we will consider white through purple to be 1 through 4 respectively, though the internal names do not follow a straight numerical order. So basically, a white gun spawns with body 1 and material 1 and so on. A unique will always spawn with body 3 (blue) with a unique material, an E-tech will always spawn with body 4 (purple) and a legendary will also spawn with body 4, with a unique material.
Now we have to look at prefixes and titles. Prefixes are mostly determined by the accessory part the gun spawns with, if no accessory is spawned, the element, and if no accessory or element, (like with whites) the prefix is determined by the grip. The title of the gun is set by the barrel it spawns with (i.e. an assault rifle that spawns with a Vladof minigun barrel will be XXXXX minigun, etc.).
At this point my best guess is that rarity is chosen before all else. This makes the most sense because there are a few parts dependent on it (body, material) then a manufacture is chosen, then a barrel would be chosen, setting its title (or maybe vice versa, it chooses a title, setting the appropriate barrel). From there you probably get the grip, then the accessory/element, then stock/sights/handle. (Shotguns don't have a separate grip and stock, so the grip is the stock, and the handle is the bit up front under the barrel. Pistols don't have a stock, but a stock accessory.)
Rarity does matter as far as stats are concerned. I have not studied in detail the exact stats per rarity, but I have tested it a bit and there is a somewhat linear progression from white to purple in terms of quality of stats, as I have illustrated with a series of Vladof pistols.
In the above example you can clearly see the linear progression from white to orange as the barrel, grip and accessory are the same. The parts shown are the Vladof barrel, grip, sight, and the fire rate accessory. this is the same for each spawn except for the white gun. because the Vladof pistol barrel will not spawn at the white rarity, I opted for Tediore, which is pretty common. with this in mind, when you start mixing up the parts you will see more varied results as they change the stats from one gun to the next. You may have a blue with a high damage from a particular part and/or accessory, and a purple right next to it (at the same level) that has similar damage, if not less from the effects of other parts or accessories.
Somehow the better the color doesn't always mean better weapon than previous color. I had a lvl 9 Blue Shotgun (sorry forgot the name) with my lvl 7 Green Shotgun. From the looks of the stat, the Blue one is definitely more powerful. But it turned out the weapon didn't have a good projectile shots and it takes 2 ammo per shot which is really not my playstyle. So in conclusion, better color then better stats but that doesn't guarantee to suit with your playstyle.
Ive had a purple pistol that was better than my orange sniper so color doesnt matter. Color only matters in rarity, effects, and worth. Hope this helped